0
我幾乎瞭解與扭曲的多處理所有的問題,但我想知道如何配置我的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]))
我怎樣才能改變我的第一個代碼來獲取輸出就像我的第二個代碼示例但作爲服務和進程化?