[英]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: 如果我使用以下命令运行main.py:
twistd -y main.py
I got 2 "some log...." lines. 我有2条“一些日志...”行。
If this code run twice? 如果此代码运行两次?
The "process name" feature you're using works by re-executing the process with a new argv[0]
. 您正在使用的“进程名称”功能通过使用新的
argv[0]
重新执行该进程来实现。 There is no completely reliable way to save an arbitrary object (like the Application) across this process re-execution. 在此过程重新执行过程中,没有完全可靠的方法来保存任意对象(如Application)。 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.
这意味着必须在新过程中重新评估.py文件,才能重新创建Application对象,从而使Twisted知道要执行的操作。
You might want to consider using setproctitle
rather than twistd
's built-in process title feature. 您可能要考虑使用
setproctitle
而不是twistd
的内置进程标题功能。 (For that matter, maybe twistd
should just use it if it's available...) (就此而言,如果可用,也许应该只使用
twistd
...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.