Gregory P. Smith <g...@krypto.org> added the comment:

Within the logging module we could go beyond using a WeakSet and maintain an 
ordering.  But we'd need to allow a way for Handler subclasses to indicate what 
order matters; that'd require a new API (not suitable for 3.7)

An ordering itself may be insufficient as code can implement arbitrary Handler 
code with cyclic graphs of handlers calling directly into other handlers such 
that no possible order could ever satisfy them all.

This pulls us back into "stop having multiple locks" for any code that creates 
relationships between handlers.  Which is good advice for Handler authors and 
something we should document if it isn't already.

Side note: We should also document that Handler.emit() as an API MUST be called 
with the Handler's lock acquired via Handler.acquire() first.  That is the 
undocumented contracted way logging.Logger.handle()'s code always calls into 
handler emit()....  The libreswan code calling other handler's emit() methods 
without doing that smells wrong.  But that has no relation to their current 
problem: Even if it did, it'd still deadlock, just sooner rather than within 
the other handler's emit()->flush()->acquire() call chain.

Logging library users are better off never directly calling another handler.  
Put message onto queues with a dedicated thread processing those into the 
relevant handlers.  Only block waiting for those queued items to have been 
processed _after_ releasing your own lock if you want to maintain the 
synchronicity of logging API calls returning only after the message has been 
handled.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36533>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to