Why Twisted Manhole ConnectionDone is an error?

python, twisted

Solution

ConnectionDone() instance is given to connectionLost() callback after the connection has been closed. You should be seeing this, when the client side decides to close the connection. You definitely don't want to filter the Failure out. You can think of the failure as a "asynchronous analogy" of the Exception. The usual thing to do, not to see some kind of exceptions is something like:

from twisted.internet import error

...

def connectionLost(self, reason):
    if reason.check(error.ConnectionDone):
        # this is normal, ignore this
        pass
    else:
        # do whatever you have been doing for logging

Problem

I'm using twisted manhole (https://github.com/HoverHell/pyaux/blob/master/pyaux/runlib.py#L126), and I also send errors caught by Twisted into python logging (https://github.com/HoverHell/pyaux/blob/master/pyaux/twisted_aux.py#L9). However, as a result, the log gets `ConnectionDone()` errors, which isn't a very interesting thing as an error. What would be appropriate to change to avoid getting this (and, possibly, some other) not-exactly-errors? Filtering for `twisted.python.failure.Failure` cases, perhaps? And where from is the ConnectionDone() even raised and why?

Original source