Skip to content

Commit 64a53be

Browse files
committed
[bpo-6721] Sanitize logging locks while forking.
1 parent 53c427e commit 64a53be

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/logging/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ def _releaseLock():
225225
if _lock:
226226
_lock.release()
227227

228+
# Prevent a held logging lock from blocking a child from logging.
229+
os.register_at_fork(before=_acquireLock,
230+
after_in_child=_releaseLock,
231+
after_in_parent=_releaseLock)
232+
228233
#---------------------------------------------------------------------------
229234
# The logging record
230235
#---------------------------------------------------------------------------
@@ -795,6 +800,9 @@ def createLock(self):
795800
Acquire a thread lock for serializing access to the underlying I/O.
796801
"""
797802
self.lock = threading.RLock()
803+
os.register_at_fork(before=self.acquire,
804+
after_in_child=self.release,
805+
after_in_parent=self.release)
798806

799807
def acquire(self):
800808
"""

0 commit comments

Comments
 (0)