Can reactor.connectTCP occur after reactor.run in twisted python?

一笑奈何 提交于 2019-12-23 17:18:33

问题


I wish to add more protocols and factories after reactor runs. I couldn't find documentation which says this is allowed. When I make reactor.run before reactor.connectTCP, the program hangs around buildProtocol in factory. Is it possible to add reactor.connectTCP to the reactor after reactor.run?


回答1:


Yes, you can start or stop listening on a TCP port at any time in Twisted. However, code like

reactor.run()
reactor.listenTCP(...)

won't work because run() only returns when the reactor has been stopped and the program is ready to exit. So you need to call listenTCP in response to something.

Also, don't use listenTCP directly; it's a very low-level API. Instead, use Endpoints.



来源:https://stackoverflow.com/questions/32014198/can-reactor-connecttcp-occur-after-reactor-run-in-twisted-python

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