holsety
holsety

Reputation: 323

using twistd to run a twisted application but script run twice

sample code here

# main.py
from twisted.application import service, internet

application = service.Application("x")
service.IProcess(application).processName = "x"

print "some log...."

if I run this main.py with:

twistd -y main.py

I got 2 "some log...." lines.

If this code run twice?

enter image description here

Upvotes: 0

Views: 174

Answers (2)

Glyph
Glyph

Reputation: 31860

You might want to consider using setproctitle rather than twistd's built-in process title feature. (For that matter, maybe twistd should just use it if it's available...)

Upvotes: 0

Jean-Paul Calderone
Jean-Paul Calderone

Reputation: 48335

The "process name" feature you're using works by re-executing the process with a new argv[0]. There is no completely reliable way to save an arbitrary object (like the Application) across this process re-execution. This means that the .py file has to be re-evaluated in the new process to recreate the Application object so twistd knows what you want it to do.

Upvotes: 2

Related Questions