【发布时间】:2016-12-06 12:36:05
【问题描述】:
我在使用twisted.internet.reactor 时遇到问题,我所有的客户都有完全相同的环境,但只有一些人遇到了这个问题:
他们通过ws 正确地connectTCP 到服务器并交换前几条消息。大约一分钟后,他们应该通过
def execute(self, message, callback=None):
print(">>>", message, flush=True)
reactor.callFromThread(self._client_protocol_instance.send, message, callback)
self._client_protocol_instance.send方法定义如下:
def send(self, command, callback):
print("send", command, callback, flush=True)
timestamp = int(time() * 1000000)
msg = (command.strip() + " --timestamp:" + str(timestamp))
if _self._debug:
_self._commands[str(timestamp)] = msg
if callback is not None:
_self._callbacks[str(timestamp)] = callback
payload = msg.encode()
_self._status_controller.set_state(payload)
self.sendMessage(payload)
第一个print 出现在标准输出中,但第二个没有。我假设send 没有被执行。在reactor.run()之后,这是整个程序中对reactor的唯一引用。
发生这种情况后,服务器会立即检测到终止客户端的进程,因此当时连接仍然存在。
这可能是什么原因造成的?
【问题讨论】: