[Twisted-Python] RE: Write into a persistent connection befor estopping

Jean-Paul Calderone exarkun at divmod.com
Mon Jan 26 11:15:22 EST 2009

On Mon, 26 Jan 2009 17:07:23 +0100, "Boeuf, Jean-Francois" <jean-francois.boeuf at eads.com> wrote:
>> [snip]
>I'm Ok with that but it is no more than test sample code. The server does
>write periodically the connection but doesn't send "<strong>Connection
>closed because of server shutdown</strong>" whereas the onStop method is
>correctly called!

This is probably because the reactor stops before the bytes are actually
sent.  You may need to delay reactor shutdown until you know the bytes
have been sent.  This may mean waiting for the connections to close or
it may mean waiting for a timeout to expire or it may mean something
else - it depends on which precise behavior you want.

"before" "shutdown" hooks can return a Deferred.  The shutdown process
will pause until that Deferred fires.  This lets you make the reactor
wait for whatever extra events you want it to wait for.


More information about the Twisted-Python mailing list