python - 扭曲的 ReconnectingClientFactory 失败且没有错误

标签 python twisted

今天我为您提供的是以下日志:

2014-11-17 08:26:35-0500 [-] Log opened.
2014-11-17 08:26:35-0500 [-] twistd 14.0.2 (/usr/bin/python 2.7.8) starting up.
2014-11-17 08:26:35-0500 [-] reactor class: twisted.internet.epollreactor.EPollReactor.
2014-11-17 08:26:35-0500 [-] Starting factory <crawl_client.WhoisClientProtocolFactory instance at 0x7fc162a36440>
2014-11-17 08:26:35-0500 [Uninitialized] <twisted.internet.tcp.Connector instance at 0x7fc168b7fe60> will retry in 2 seconds
2014-11-17 08:26:35-0500 [Uninitialized] Stopping factory <crawl_client.WhoisClientProtocolFactory instance at 0x7fc162a36440>
2014-11-17 08:26:37-0500 [-] Starting factory <crawl_client.WhoisClientProtocolFactory instance at 0x7fc162a36440>
2014-11-17 08:26:37-0500 [Uninitialized] <twisted.internet.tcp.Connector instance at 0x7fc168b7fe60> will retry in 4 seconds
2014-11-17 08:26:37-0500 [Uninitialized] Stopping factory <crawl_client.WhoisClientProtocolFactory instance at 0x7fc162a36440>
2014-11-17 08:26:42-0500 [-] Starting factory <crawl_client.WhoisClientProtocolFactory instance at 0x7fc162a36440>
2014-11-17 08:26:42-0500 [Uninitialized] <twisted.internet.tcp.Connector instance at 0x7fc168b7fe60> will retry in 14 seconds
2014-11-17 08:26:42-0500 [Uninitialized] Stopping factory <crawl_client.WhoisClientProtocolFactory instance at 0x7fc162a36440>
2014-11-17 08:26:57-0500 [-] Starting factory <crawl_client.WhoisClientProtocolFactory instance at 0x7fc162a36440>

这是工厂代码:

from twisted.internet.protocol import ReconnectingClientFactory
from uuid import uuid4

class WhoisClientProtocolFactory(ReconnectingClientFactory):

  def __init__(self, clientName='', maxDelay=60):
    # attach a name with the client to identify itself to the server
    if not clientName:
      clientName = str(uuid4())[:8] # first 8 characters from a random string
    self.client_name = clientName
    self.maxDelay = maxDelay
    logFromClient("client started", logging.INFO, clientName)

  def buildProtocol(self, addr):
    self.resetDelay()
    return MyClientProtocol(self.client_name)

这段代码在我的测试机上运行良好。当部署在服务器上时,它会绕圈走。我怎样才能找到造成这种情况的原因? 顺便说一句,客户端基于 LineReceiver

谢谢

最佳答案

当连接尝试失败时,工厂的 clientConnectionFailed方法被调用。 ReconnectingClientFactory 实现此方法以添加重试行为和您看到的给出退避超时的最小日志记录。

您也可以重写此方法。引入您想要的额外日志记录 - 连接失败的原因作为参数传递给此方法 - 然后调用基本实现(以保留重试行为)。

原因为 Failure实例。

关于python - 扭曲的 ReconnectingClientFactory 失败且没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26974119/

相关文章:

Python 生成 sdist 并在单独的步骤中上传

python - OpenCV 错误:(-215:断言失败)函数 'CvtHelper' 中的 VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth)

python - 在异步代码中使用 PIL (Twisted Web)

javascript - Node.js 与 Twisted 的用例是什么?

python - 使用队列以扭曲方式下载文件

python - Paramiko 获取排序的目录列表

python - 如何使用 mstats.kruskalwallis

python - 如何在 python 中为多个数据帧形成矩阵或表格(重叠计数)

python - 扭曲的视角经纪人服务器端延迟

Django 和 Websockets : How to create, 在同一个进程中,一个同时具有 WSGI 和 websockets 的高效项目吗?