From: Vinay Sajip Date: Sat, 25 Sep 2010 17:42:36 +0000 (+0000) Subject: Issue #9945: logging: Fixed locking bugs in addHandler/removeHandler. X-Git-Tag: v2.7.1rc1~241 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=546885ea4e3d1360bfc43d3890497aa91180d98d;p=python Issue #9945: logging: Fixed locking bugs in addHandler/removeHandler. --- diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index c8e5ac290c..e1dbbc03aa 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1263,20 +1263,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.close() - hdlr.acquire() - try: + _acquireLock() + try: + if hdlr in self.handlers: self.handlers.remove(hdlr) - finally: - hdlr.release() + finally: + _releaseLock() def callHandlers(self, record): """ diff --git a/Misc/NEWS b/Misc/NEWS index 77adf82beb..e6acb856d9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -43,6 +43,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 #9928: Properly initialize the types exported by the bz2 module.