[issue10462] Handler.close is not called in subclass while Logger.removeHandler is called
report at bugs.python.org
Sat Nov 20 15:33:41 CET 2010
Vinay Sajip <vinay_sajip at yahoo.co.uk> added the comment:
The reason for this behaviour is as follows: the internal list of handlers now uses weak references, see
If there are no references to a handler, it can disappear at any time: and if it does, then it won't get closed at shutdown.
If there are references to it, then the shutdown code will close all handlers on application exit.
So: either leave references to your handlers, or close them when you're done with them, or add a __del__() which will call close() when the handler is garbage collected.
BTW removeHandler() does not call close(), and never has - these are two distinct operations.
It wouldn't be right for the logging package to automatically call close() on handlers, except at application exit - where the main reason for doing so is to flush any pending output and release any resources used by the handler.
Note that adding a __del__(self): self.close() method to MyHandler results in the close() being called [during garbage collection].
resolution: -> invalid
status: open -> closed
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list