Python扭曲守护进程

Python扭曲守护进程,python,twisted,twisted.web,twisted.client,twisted.internet,Python,Twisted,Twisted.web,Twisted.client,Twisted.internet,我编写了一个简单的twisted服务器- from twisted.internet import reactor from twisted.internet import protocol from twisted.web import server, resource from twisted.internet import reactor class Index(resource.Resource): isLeaf = True def render_GET(self,

我编写了一个简单的twisted服务器-

from twisted.internet import reactor
from twisted.internet import protocol
from twisted.web import server, resource
from twisted.internet import reactor

class Index(resource.Resource):
    isLeaf = True
    def render_GET(self, request):
        args = request.args
        print 'Args: %s' %(repr(args))

print 'Serving on PORT: 8090'
site = server.Site(Index())
reactor.listenTCP(8090, site)
reactor.run()

这在
127.0.0.1:8090上运行良好。请注意,当我使用
nohup
ctrl+Z
使进程在后台运行时,它在终端(前台)中运行。服务器不响应请求。我应该怎么做才能将这个twisted服务器后台监控

我建议查看twisted。这样,您就不必担心处理任何启动、pid文件管理等问题。他们网站上的文档非常好:。还要检查如何实现应用程序文件。

正如nmichael和Rakis已经提到的,在“ctrl+z”之后键入“bg”以恢复挂起的进程作为后台作业

要直接将其作为后台作业运行,请键入

python myserver.py &
要直接将其作为后台作业运行,并且在注销时不会停止,请键入

nohup python myserver.py &
还要注意的是,
nohup
,不是真正的去名字化。请参见此处的差异:


如果你真的想取消Twisted服务器的名字,最好的选择是使用Mark Loeser回答的
Twisted

你是真的将它背景化了,还是仅仅用ctrl+z暂停它?我试过了
ctrl+z
。在shell中键入“ctrl+z”后,我如何将其取消命名。这将作为后台工作恢复暂停的进程。我已经这样做了&它起作用了。因为nmicheal的答案不是一个真正的答案,不能投票或打分…这不是真正的恶魔化。例如,当您关闭终端窗口时,stdin、stdout和stderr将消失。@Glyph当然。这就是为什么我有最后一句话“但是如果你真的想让它去名字化,就用马克·洛瑟回答的twistd。”我只回答了如何在后台运行,或者使用
nohup
,而不是去名字化它。