扭曲的ReconnectingClientFactory失败而没有错误

时间:2014-11-17 13:48:24

标签: 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

由于

1 个答案:

答案 0 :(得分:1)

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

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

原因是Failure个实例。