Thanks for the link. Looking at your code I found the magic lines I was missing. Implementing my own HTTPChannel was the key to success. Now I don't have to poll reactor.getWriters() to see if there are unfinished writers. I ended up with something like this: class ApiHTTPChannel(HTTPChannel): _connection_lost = None def notifyConnectionLost(self): if self._connection_lost is not None: return self._connection_lost return defer.succeed(None) def connectionMade(self): HTTPChannel.connectionMade(self) self._connection_lost = defer.Deferred() def connectionLost(self, reason): HTTPChannel.connectionLost(self, reason) self._connection_lost.callback(None) Thanks On 28 August 2013 18:09, Aaron Gallagher <_@habnab.it> wrote:
I didn't read over your code, but this is something that I've independently implemented. You can see my implementation at https://github.com/habnabit/polecat/blob/master/polecat.py. The Site subclass does some other monitoring-related things, but you should be able to tease out just the graceful shutdown parts if that's all you want.
Polecat needs some work and a lot of documentation, but for now, the way to do a graceful shutdown is to make a PolecatSite and then addSystemEventTrigger('before', 'shutdown', yourPolecatSite.gracefullyStopActiveClients).
-- /Jonas