【发布时间】:2013-11-29 15:42:45
【问题描述】:
当使用 Twisted ReconnectingClientFactory 并且连接丢失时,我需要从 clientConnectionLost 方法中调用 connector.connect() 还是自动发生?
答案可能看起来很明显,因为它毕竟是 ReconnectingClientFactory,但 Twisted 文档说 here 让我想知道:
“调用connector.connect()可能有用——这将重新连接。”
“可能有用”一词的措辞和使用导致了这个问题,因为基本客户端工厂的 api 文档说了同样的话。
Max 的答案是正确的,但经过进一步研究,我认为“更正者”的答案如下:
def clientConnectionLost(self, connector, reason):
# do stuff here that is unique to your own requirements, then:
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
这允许您执行应用程序所需的特殊操作,然后调用工厂代码以允许 Twisted 为您调用 retry()。
【问题讨论】:
标签: twisted twisted.internet twisted.client