问题描述
我希望在反应堆运行后添加更多协议和工厂.我找不到说明这是允许的文档.当我在Reactor.connectTCP之前执行react-.run时,该程序在工厂中围绕buildProtocol挂起.在react..run之后可以将react..connectTCP添加到反应器吗?
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?
推荐答案
是的,您可以随时在Twisted中启动或停止监听TCP端口.但是,像
Yes, you can start or stop listening on a TCP port at any time in Twisted. However, code like
reactor.run()
reactor.listenTCP(...)
无效,因为run()
仅在反应堆已停止且程序准备退出时返回.因此,您需要致电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.
此外,请勿直接使用listenTCP
;这是一个非常低级的API.而是使用端点.
Also, don't use listenTCP
directly; it's a very low-level API. Instead, use Endpoints.
这篇关于在Reactor.Run中以扭曲的python运行之后,reactor.connectTCP会发生吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!