0

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

holsety
  • 323
  • 1
  • 2
  • 13

2 Answers2

2

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.

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122
  • yes! I removed service.IProcess(application).processName = "x" and it print one line log now.But it is still a little weird – holsety Dec 25 '14 at 23:49
0

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...)

Glyph
  • 31,152
  • 11
  • 87
  • 129