Index: Lib/logging/__init__.py =================================================================== --- Lib/logging/__init__.py (revision 61169) +++ Lib/logging/__init__.py (working copy) @@ -585,6 +585,7 @@ Filterer.__init__(self) self.level = level self.formatter = None + self.loggers = [] # list of all loggers this handler is in #get the module data lock, as we're updating a shared structure. _acquireLock() try: #unlikely to raise an exception, but you never know... @@ -690,6 +691,10 @@ """ #get the module data lock, as we're updating a shared structure. _acquireLock() + + #remove this handler from all loggers that are using it + while self.loggers: + self.loggers[0].removeHandler(self) try: #unlikely to raise an exception, but you never know... del _handlers[self] _handlerList.remove(self) @@ -1138,6 +1143,7 @@ """ if not (hdlr in self.handlers): self.handlers.append(hdlr) + hdlr.loggers.append(self) # inform the handler it has been attached def removeHandler(self, hdlr): """ @@ -1145,6 +1151,7 @@ """ if hdlr in self.handlers: #hdlr.close() + hdlr.loggers.remove(self) # inform the handler it has been detached hdlr.acquire() try: self.handlers.remove(hdlr)