gpt4 book ai didi

Python Twisted 守护进程

转载 作者:行者123 更新时间:2023-11-28 19:46:02 25 4
gpt4 key购买 nike

我写了一个简单的扭曲服务器 -

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 上运行良好。请注意,当我使用 nohupctrl+Z 让进程在后台运行时,它在终端(前台)中运行。服务器不响应请求。我应该怎么做才能守护这个扭曲的服务器

最佳答案

我建议研究 twistd。这样您就不必担心处理任何启动、pid 文件管理等。他们网站上的文档非常好:http://twistedmatrix.com/documents/current/core/howto/basics.html .还要检查 http://twistedmatrix.com/documents/current/core/howto/tap.html如何实现应用文件。

关于Python Twisted 守护进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4617987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com