<div dir="ltr">Thanks for the link. Looking at your code I found the magic lines I was missing.<div><br></div><div>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.</div>

<div><br></div><div>I ended up with something like this:</div><div><div>class ApiHTTPChannel(HTTPChannel):</div><div>    _connection_lost = None</div><div><br></div><div>    def notifyConnectionLost(self):</div><div>        if self._connection_lost is not None:</div>

<div>            return self._connection_lost</div><div>        return defer.succeed(None)</div><div><br></div><div>    def connectionMade(self):</div><div>        HTTPChannel.connectionMade(self)</div><div>        self._connection_lost = defer.Deferred()</div>

<div><br></div><div>    def connectionLost(self, reason):</div><div>        HTTPChannel.connectionLost(self, reason)</div><div>        self._connection_lost.callback(None)</div></div><div><br></div><div>Thanks</div></div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On 28 August 2013 18:09, Aaron Gallagher <span dir="ltr"><<a href="mailto:_@habnab.it" target="_blank">_@habnab.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I didn't read over your code, but this is something that I've<br>
independently implemented. You can see my implementation at<br>
<<a href="https://github.com/habnabit/polecat/blob/master/polecat.py" target="_blank">https://github.com/habnabit/polecat/blob/master/polecat.py</a>>. The Site<br>
subclass does some other monitoring-related things, but you should be<br>
able to tease out just the graceful shutdown parts if that's all you<br>
want.<br>
<br>
Polecat needs some work and a lot of documentation, but for now, the way<br>
to do a graceful shutdown is to make a PolecatSite and then<br>
addSystemEventTrigger('before', 'shutdown',<br>
yourPolecatSite.gracefullyStopActiveClients).<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>/Jonas<br>
</div>