Non-blocking server in Twisted

与世无争的帅哥 提交于 2019-12-22 07:36:37

问题


I am building an application that needs to run a TCP server on a thread other than the main. When trying to run the following code:

reactor.listenTCP(ServerConfiguration.tcpport, TcpCommandFactory())
reactor.run()

I get the following error

exceptions.ValueError: signal only works in main thread

Can I run the twisted servers on threads other than the main one?


回答1:


Twisted can run in any thread - but only one thread at a time. If you want to run in the non-main thread, simply do reactor.run(installSignalHandlers=False). However, you cannot use a reactor on the non-main thread to spawn subprocesses, because their termination will never be detected. (This is a limitation of UNIX, really, not of Twisted.)



来源:https://stackoverflow.com/questions/12917980/non-blocking-server-in-twisted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!