我几乎读过关于使用twisted.application.service进行多处理的所有问题,但是我想知道如何使用部署我的TCP应用程序,我有以下代码可以使用服务来部署我的工厂:
from project.application import GameServerFactory
from twisted.application import internet, service
port = 8000
factory = GameServerFactory()
application = service.Application("Game Server")
service = internet.TCPServer(port, factory)
service.setServiceParent(application)但我想像这样使用我的所有核心(我从另一个问题中复制):
from project.application import GameServerFactory
from os import environ
from sys import argv, executable
from socket import AF_INET
import sys
from twisted.internet import reactor
def main(fd=None):
factory = GameServerFactory()
if fd is None:
# Create a new listening port and several other processes to help out.
port = reactor.listenTCP(8000, factory)
for i in range(7):
reactor.spawnProcess(
None, executable, [executable, __file__, str(port.fileno())],
childFDs={0: 0, 1: 1, 2: 2, port.fileno(): port.fileno()},
env=environ)
#sys.exit()
else:
# Another process created the port, just start listening on it.
port = reactor.adoptStreamPort(fd, AF_INET, factory)
reactor.run()
if __name__ == '__main__':
if len(argv) == 1:
main()
else:
main(int(argv[1]))如何更改第一段代码以获得输出,就像我的第二个代码示例一样,但作为服务和守护进程?
发布于 2016-03-05 05:00:28
最后,我决定使用HAProxy前端的(n)过程的扭曲。
https://stackoverflow.com/questions/34797135
复制相似问题