[Twisted-Python] Logging observers and threads

Tristan Seligmann mithrandi at mithrandi.net
Thu Jul 12 05:17:42 EDT 2012

When an error occurs in a database connection thread, adbapi invokes
log.err from that thread, which in turns causes log observers to be
invoked in this thread. Mantissa's TracebackCollector has a log
observer which logs items as Items in an Axiom store; this means that
the log observer tries to run SQLite queries in the wrong thread, and
explodes. However, I'm not sure whose fault this is; it seems there
are three possibilities:

1) log.err and log.msg should not be called from a non-reactor thread,
making this an adbapi bug.
2) twisted.python.log should not invoke log observers in a non-reactor
thread, making this a twisted.python.log bug.
3) log observers should expect to be inovked in non-reactor threads,
making this a Mantissa bug.

Can anyone give a definitive answer on this? The "nothing except
reactor.callFromThread is thread-safe" principle would suggest that 1)
is the case, but logging seems like it might be a special case.
mithrandi, i Ainil en-Balandor, a faer Ambar

More information about the Twisted-Python mailing list