summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2010-09-11 09:06:21 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2010-09-11 09:06:21 (GMT)
commit1ab32f6ebebe6041fae41f573963bfa8b31df1a1 (patch)
tree02b255deb387a3de104d29f4fd196a0ffaab9224 /Lib/logging
parent588bd847fb538397ad9239e624e832b53e0b0988 (diff)
downloadcpython-1ab32f6ebebe6041fae41f573963bfa8b31df1a1.zip
cpython-1ab32f6ebebe6041fae41f573963bfa8b31df1a1.tar.gz
cpython-1ab32f6ebebe6041fae41f573963bfa8b31df1a1.tar.bz2
logging: Added threading interlock in basicConfig().
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 5922ed3..c8e5ac2 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1497,22 +1497,28 @@ def basicConfig(**kwargs):
using sys.stdout or sys.stderr), whereas FileHandler closes its stream
when the handler is closed.
"""
- if len(root.handlers) == 0:
- filename = kwargs.get("filename")
- if filename:
- mode = kwargs.get("filemode", 'a')
- hdlr = FileHandler(filename, mode)
- else:
- stream = kwargs.get("stream")
- hdlr = StreamHandler(stream)
- fs = kwargs.get("format", BASIC_FORMAT)
- dfs = kwargs.get("datefmt", None)
- fmt = Formatter(fs, dfs)
- hdlr.setFormatter(fmt)
- root.addHandler(hdlr)
- level = kwargs.get("level")
- if level is not None:
- root.setLevel(level)
+ # Add thread safety in case someone mistakenly calls
+ # basicConfig() from multiple threads
+ _acquireLock()
+ try:
+ if len(root.handlers) == 0:
+ filename = kwargs.get("filename")
+ if filename:
+ mode = kwargs.get("filemode", 'a')
+ hdlr = FileHandler(filename, mode)
+ else:
+ stream = kwargs.get("stream")
+ hdlr = StreamHandler(stream)
+ fs = kwargs.get("format", BASIC_FORMAT)
+ dfs = kwargs.get("datefmt", None)
+ fmt = Formatter(fs, dfs)
+ hdlr.setFormatter(fmt)
+ root.addHandler(hdlr)
+ level = kwargs.get("level")
+ if level is not None:
+ root.setLevel(level)
+ finally:
+ _releaseLock()
#---------------------------------------------------------------------------
# Utility functions at module level.