Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a0fc97

Browse files
committed
merge cl r68737 to py3k
1 parent e1cdfd7 commit 9a0fc97

3 files changed

Lines changed: 13 additions & 24 deletions

File tree

Lib/logging/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ def currentframe():
9898
#
9999
logThreads = 1
100100

101+
#
102+
# If you don't want multiprocessing information in the log, set this to zero
103+
#
104+
logMultiprocessing = 1
105+
101106
#
102107
# If you don't want process information in the log, set this to zero
103108
#
@@ -263,6 +268,11 @@ def __init__(self, name, level, pathname, lineno,
263268
else:
264269
self.thread = None
265270
self.threadName = None
271+
if logMultiprocessing:
272+
from multiprocessing import current_process
273+
self.processName = current_process().name
274+
else:
275+
self.processName = None
266276
if logProcesses and hasattr(os, 'getpid'):
267277
self.process = os.getpid()
268278
else:

Lib/multiprocessing/util.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,10 @@ def get_logger():
6969
atexit._exithandlers.remove((_exit_function, (), {}))
7070
atexit._exithandlers.append((_exit_function, (), {}))
7171

72-
_check_logger_class()
7372
_logger = logging.getLogger(LOGGER_NAME)
7473

7574
return _logger
7675

77-
def _check_logger_class():
78-
'''
79-
Make sure process name is recorded when loggers are used
80-
'''
81-
# XXX This function is unnecessary once logging is patched
82-
import logging
83-
if hasattr(logging, 'multiprocessing'):
84-
return
85-
86-
logging._acquireLock()
87-
try:
88-
OldLoggerClass = logging.getLoggerClass()
89-
if not getattr(OldLoggerClass, '_process_aware', False):
90-
class ProcessAwareLogger(OldLoggerClass):
91-
_process_aware = True
92-
def makeRecord(self, *args, **kwds):
93-
record = OldLoggerClass.makeRecord(self, *args, **kwds)
94-
record.processName = current_process()._name
95-
return record
96-
logging.setLoggerClass(ProcessAwareLogger)
97-
finally:
98-
logging._releaseLock()
99-
10076
def log_to_stderr(level=None):
10177
'''
10278
Turn on logging and add a handler which prints to stderr

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ Core and Builtins
132132
Library
133133
-------
134134

135+
- Issue #4301: Patch the logging module to add processName support, remove
136+
_check_logger_class from multiprocessing.
137+
135138
- Issue #3325: Remove python2.x try: except: imports for old cPickle from
136139
multiprocessing.
137140

0 commit comments

Comments
 (0)