当使用 Twisted ReconnectingClientFactory 并且连接丢失时,我需要从 clientConnectionLost 方法中调用 connector.connect() 还是自动发生这种情况?
答案可能看起来很明显,因为它毕竟是 ReconnectingClientFactory但 Twisted 文档在这里说了一些让我想知道的东西:
“调用 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()。