[Python-checkins] cpython (merge 3.4 -> default): Closes #21149: Improved thread-safety in logging cleanup during interpreter
python-checkins at python.org
Fri Apr 4 11:57:47 CEST 2014
user: Vinay Sajip <vinay_sajip at yahoo.co.uk>
date: Fri Apr 04 10:57:25 2014 +0100
Closes #21149: Improved thread-safety in logging cleanup during interpreter shutdown.
Lib/logging/__init__.py | 17 +++++++++--------
Misc/NEWS | 3 +++
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
@@ -711,16 +711,17 @@
Remove a handler reference from the internal cleanup list.
# This function can be called during module teardown, when globals are
- # set to None. If _acquireLock is None, assume this is the case and do
- # nothing.
- if (_acquireLock is not None and _handlerList is not None and
- _releaseLock is not None):
+ # set to None. It can also be called from another thread. So we need to
+ # pre-emptively grab the necessary globals and check if they're None,
+ # to prevent race conditions and failures during interpreter shutdown.
+ acquire, release, handlers = _acquireLock, _releaseLock, _handlerList
+ if acquire and release and handlers:
- if wr in _handlerList:
+ if wr in handlers:
diff --git a/Misc/NEWS b/Misc/NEWS
@@ -29,6 +29,9 @@
+- Issue #21149: Improved thread-safety in logging cleanup during interpreter
+ shutdown. Thanks to Devin Jeanpierre for the patch.
- Issue #21058: Fix a leak of file descriptor in
:func:`tempfile.NamedTemporaryFile`, close the file descriptor if
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins