Twisted ReconnectingClientFactory - 自动重新连接或显式调用 connector.connect()?

标签 twisted twisted.internet twisted.client

当使用 Twisted ReconnectingClientFactory 并且连接丢失时,我是否需要从 clientConnectionLost 方法中调用 connector.connect() 还是自动发生?

答案似乎很明显,因为毕竟它是 ReconnectingClientFactory 但 Twisted 文档说明了一些事情 here这让我想知道:

"It may be useful to call connector.connect() - this will reconnect."

术语“可能有用”的措辞和使用引出了问题,因为基本客户端工厂的 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()。

最佳答案

我的旧答案并不完全正确。而是这样做:

def clientConnectionLost(self, connector, reason):
    # do stuff here that is unique to your own requirements, then:
    ReconnectingClientFactory.clientConnectionLost(self, connector, reason)

This allows you to do specialised things required by your application and then call into the factory code to allow Twisted to take care of calling retry() for you.

关于Twisted ReconnectingClientFactory - 自动重新连接或显式调用 connector.connect()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20014776/

相关文章:

ssl - 带有延迟的扭曲 SNI

python - 使用 stringIO 对象作为 ssl key /证书文件

python - 将异步扭曲代码集成到同步 python 代码中

python - 扭曲的线程......如何正确使用它们?

python - 手动给扭曲(Web)网络堆栈一个数据包来处理?

python - 了解 Twisted 和异步编程。为什么一段代码有效而另一段代码无效?

twisted - 使用另一个 Socket/TCP/RPC 服务扩展现有的 Twisted 服务以获取服务信息

python - 发出 GET 请求,然后用 Python (Twisted) 打印出响应体

Python Twisted 客户端连接丢失