From 32fb6a81f992d86bb4c227912602c224dbbc7d7f Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Sat, 25 Sep 2010 17:42:36 +0000 Subject: [PATCH] Issue #9945: logging: Fixed locking bugs in addHandler/removeHandler. --- Lib/logging/__init__.py | 18 +++++++++++------- Misc/NEWS | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 4c3dd1539d..79ec9ef7d5 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1226,19 +1226,23 @@ class Logger(Filterer): """ Add the specified handler to this logger. """ - if not (hdlr in self.handlers): - self.handlers.append(hdlr) + _acquireLock() + try: + if not (hdlr in self.handlers): + self.handlers.append(hdlr) + finally: + _releaseLock() def removeHandler(self, hdlr): """ Remove the specified handler from this logger. """ - if hdlr in self.handlers: - hdlr.acquire() - try: + _acquireLock() + try: + if hdlr in self.handlers: self.handlers.remove(hdlr) - finally: - hdlr.release() + finally: + _releaseLock() def hasHandlers(self): """ diff --git a/Misc/NEWS b/Misc/NEWS index 489d6a9673..c84a8ef3c4 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -68,6 +68,8 @@ Core and Builtins Library ------- +- Issue #9945: logging: Fixed locking bugs in addHandler/removeHandler. + - Issue #9936: Fixed executable lines' search in the trace module. - Issue #9790: Rework imports necessary for samefile and sameopenfile -- 2.40.0