开发者

in Twisted, wait until connection closed cleanly

开发者 https://www.devze.com 2023-01-08 02:46 出处:网络
I want to disconnect cleanly, and then stop the reactor. If I do this, however: controller.connection.disconnect()

I want to disconnect cleanly, and then stop the reactor. If I do this, however:

controller.connection.disconnect()
reactor.stop()

then I get a "开发者_运维知识库connection was lost in a non-clean fashion" message. If I insert a time.sleep(1) in between them, the connection closes cleanly. How can I wait until the connection is really closed?


You could listen for a callback from twisted which indicates that the connection has been disconnected. This blog describes an approach to do this.


I have been wondering about the same thing recently, how to disconnect my client in clean way. While the client is a subclass of LineReceiver I tried:

connector.disconnect()

self.factory.close() (where factory is IAddress returned by Factory's buildProtocol())

reactor.stop()

but what I actually found in some docs was:

self.transport.loseConnection()

and it closes connection cleanly. The question is quite old now, but I hope it would help somebody in the future :)

0

精彩评论

暂无评论...
验证码 换一张
取 消