summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing/util.py
diff options
context:
space:
mode:
authorJesse Noller <jnoller@gmail.com>2009-03-31 15:01:45 (GMT)
committerJesse Noller <jnoller@gmail.com>2009-03-31 15:01:45 (GMT)
commit8b56d47d01a4ffe3017a618a09f6ff206f6ea163 (patch)
tree6178478469f7cd11db303da718e6ee3e643d2263 /Lib/multiprocessing/util.py
parent5b19e62b88e095c4da17f3ffbcf9096e0d827245 (diff)
downloadcpython-8b56d47d01a4ffe3017a618a09f6ff206f6ea163.zip
cpython-8b56d47d01a4ffe3017a618a09f6ff206f6ea163.tar.gz
cpython-8b56d47d01a4ffe3017a618a09f6ff206f6ea163.tar.bz2
Merged revisions 68915 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r68915 | jesse.noller | 2009-01-24 21:36:13 -0600 (Sat, 24 Jan 2009) | 1 line Properly document multiprocessing's logging support, resolve outstanding issues with the custom levels ........
Diffstat (limited to 'Lib/multiprocessing/util.py')
-rw-r--r--Lib/multiprocessing/util.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py
index 2e7a2ac..632adb1 100644
--- a/Lib/multiprocessing/util.py
+++ b/Lib/multiprocessing/util.py
@@ -17,7 +17,8 @@ from multiprocessing.process import current_process, active_children
__all__ = [
'sub_debug', 'debug', 'info', 'sub_warning', 'get_logger',
'log_to_stderr', 'get_temp_dir', 'register_after_fork',
- 'is_exiting', 'Finalize', 'ForkAwareThreadLock', 'ForkAwareLocal'
+ 'is_exiting', 'Finalize', 'ForkAwareThreadLock', 'ForkAwareLocal',
+ 'SUBDEBUG', 'SUBWARNING',
]
#
@@ -57,19 +58,27 @@ def get_logger():
Returns logger used by multiprocessing
'''
global _logger
+ import logging, atexit
- if not _logger:
- import logging, atexit
+ logging._acquireLock()
+ try:
+ if not _logger:
- # XXX multiprocessing should cleanup before logging
- if hasattr(atexit, 'unregister'):
- atexit.unregister(_exit_function)
- atexit.register(_exit_function)
- else:
- atexit._exithandlers.remove((_exit_function, (), {}))
- atexit._exithandlers.append((_exit_function, (), {}))
+ _logger = logging.getLogger(LOGGER_NAME)
+ _logger.propagate = 0
+ logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
+ logging.addLevelName(SUBWARNING, 'SUBWARNING')
+
+ # XXX multiprocessing should cleanup before logging
+ if hasattr(atexit, 'unregister'):
+ atexit.unregister(_exit_function)
+ atexit.register(_exit_function)
+ else:
+ atexit._exithandlers.remove((_exit_function, (), {}))
+ atexit._exithandlers.append((_exit_function, (), {}))
- _logger = logging.getLogger(LOGGER_NAME)
+ finally:
+ logging._releaseLock()
return _logger
@@ -79,14 +88,17 @@ def log_to_stderr(level=None):
'''
global _log_to_stderr
import logging
+
logger = get_logger()
formatter = logging.Formatter(DEFAULT_LOGGING_FORMAT)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
- if level is not None:
+
+ if level:
logger.setLevel(level)
_log_to_stderr = True
+ return _logger
#
# Function returning a temp directory which will be removed on exit