开发者

twisted .loseConnection does not immediately lose connection?

I have a server with a few clients connected to it. When CTRL+C is hit (that is, reactor starts shutting down), I want to close all my connections, wait until they are cleanly closed, and then stop. I do this by going through the connected clients' transports and calling .loseConnection(). On the ones that are connected locally, they immediately disconnect. However, on one that is connected through the internet, the connection is not immediately lost. Communication stops - and closing the client program no longer even tells the server that the connection has died, although it does before calling .loseConnection() - but the connection is not deemed 'lost' until a few minutes later after I send a few heart开发者_如何学Pythonbeat requests from the server.

I understand that if a connection dies, there's no way for the server to know unless it tries to send some data. But if I specifically ask for a connection to be closed, why does it not just close/disconnect immediately? Am I calling the wrong function?


loseConnection flushes the write buffer before shutting down the connection. If you don't want to wait for that to happen, just let the reactor stop before it does. They'll get closed that way, with any unsent data in their write buffer discarded.

There's also a proposal to add an API for discarding the write buffer and disconnecting, abortConnection.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜