我写了一个简单的扭曲服务器-
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让进程在后台运行时,这将在终端(前台)运行。服务器不响应请求。我应该怎么做才能守护这个扭曲的服务器?
发布于 2011-01-09 20:30:31
正如nmichael和Rakis已经提到的,在"ctrl+z“之后键入"bg”以恢复挂起的进程作为后台作业。
要将其直接作为后台作业运行,请键入
python myserver.py &要将其作为后台作业直接运行,并且在注销时不会停止,请键入
nohup python myserver.py &还要注意的是,nohup并不是真正的去离子化。在这里看到不同之处:What's the difference between nohup and a daemon?
如果你真的想让你的Twisted服务器去功能化,最好的选择就是像Mark Loeser回答的那样使用twistd。
发布于 2011-01-07 01:58:32
我建议你调查一下twistd。这样你就不必担心任何启动、pid文件管理等问题了。他们网站上的文档相当不错:http://twistedmatrix.com/documents/current/core/howto/basics.html。另请查看http://twistedmatrix.com/documents/current/core/howto/tap.html,了解如何实现应用程序文件。
https://stackoverflow.com/questions/4617987
复制相似问题