logging: Added threading interlock in basicConfig().

This commit is contained in:
Vinay Sajip 2010-09-10 08:25:13 +00:00
parent c7937791a1
commit 2314fc729b

View file

@ -1459,6 +1459,10 @@ def basicConfig(**kwargs):
using sys.stdout or sys.stderr), whereas FileHandler closes its stream using sys.stdout or sys.stderr), whereas FileHandler closes its stream
when the handler is closed. when the handler is closed.
""" """
# Add thread safety in case someone mistakenly calls
# basicConfig() from multiple threads
_acquireLock()
try:
if len(root.handlers) == 0: if len(root.handlers) == 0:
filename = kwargs.get("filename") filename = kwargs.get("filename")
if filename: if filename:
@ -1475,6 +1479,8 @@ def basicConfig(**kwargs):
level = kwargs.get("level") level = kwargs.get("level")
if level is not None: if level is not None:
root.setLevel(level) root.setLevel(level)
finally:
_releaseLock()
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Utility functions at module level. # Utility functions at module level.