python扭曲守护程序
-
30-09-2019 - |
题
我写了一个简单的扭曲服务器 -
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
. 。服务器不响应请求。我应该怎么做才能驱动这款扭曲的服务器
解决方案
正如Nmichael和Rakis已经提到的那样,在“ Ctrl+Z”类型“ BG”之后,恢复暂停过程作为后台工作。
要直接运行作为后台作业,请输入
python myserver.py &
要直接运行它作为后台作业,在注销时不会停止,请键入
nohup python myserver.py &
另请注意 nohup
, ,不是真正的脱摩根化。请参阅此处的差异: Nohup和守护程序有什么区别?
如果您真的想删除扭曲的服务器,最好的选择是使用 twistd
正如马克·洛瑟(Mark Loeser)回答的那样。
其他提示
我建议您研究Twistd。这样,您就不必担心处理任何启动,PID文件管理等。其网站上的文档非常好: http://twistedmatrix.com/documents/current/core/howto/basics.html. 。也检查 http://twistedmatrix.com/documents/current/core/howto/tap.html 有关如何实现应用程序文件。
不隶属于 StackOverflow