Skip to content

Commit b9c85c1

Browse files
committed
Issue python#7403: logging: Fixed possible race condition in lock creation.
1 parent 4c9c260 commit b9c85c1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Lib/logging/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,17 @@ def addLevelName(level, levelName):
176176
#the lock would already have been acquired - so we need an RLock.
177177
#The same argument applies to Loggers and Manager.loggerDict.
178178
#
179-
_lock = None
179+
if thread:
180+
_lock = threading.RLock()
181+
else:
182+
_lock = None
180183

181184
def _acquireLock():
182185
"""
183186
Acquire the module-level lock for serializing access to shared data.
184187
185188
This should be released with _releaseLock().
186189
"""
187-
global _lock
188-
if (not _lock) and thread:
189-
_lock = threading.RLock()
190190
if _lock:
191191
_lock.acquire()
192192

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Core and builtins
1818
Library
1919
-------
2020

21+
- Issue #7403: logging: Fixed possible race condition in lock creation.
22+
2123
- Issue #5068: Fixed the tarfile._BZ2Proxy.read() method that would loop
2224
forever on incomplete input. That caused tarfile.open() to hang when used
2325
with mode 'r' or 'r:bz2' and a fileobj argument that contained no data or

0 commit comments

Comments
 (0)