summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2010-03-22 12:33:08 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2010-03-22 12:33:08 (GMT)
commit3017a7bbbf2046b93ac89fcbabadaf0a528e5ae1 (patch)
treec466933e672475186081099ffffd32a97cacedc4 /Lib/logging
parent95affc44495806a540f4d997d13361cc388b1a7e (diff)
downloadcpython-3017a7bbbf2046b93ac89fcbabadaf0a528e5ae1.zip
cpython-3017a7bbbf2046b93ac89fcbabadaf0a528e5ae1.tar.gz
cpython-3017a7bbbf2046b93ac89fcbabadaf0a528e5ae1.tar.bz2
Issue #8200: logging: Handle errors when multiprocessing is not fully loaded when logging occurs.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index b1810d68..088c1fc 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -287,10 +287,18 @@ class LogRecord(object):
self.threadName = None
if not logMultiprocessing:
self.processName = None
- elif 'multiprocessing' not in sys.modules:
- self.processName = 'MainProcess'
else:
- self.processName = sys.modules['multiprocessing'].current_process().name
+ self.processName = 'MainProcess'
+ mp = sys.modules.get('multiprocessing')
+ if mp is not None:
+ # Errors may occur if multiprocessing has not finished loading
+ # yet - e.g. if a custom import hook causes third-party code
+ # to run when multiprocessing calls import. See issue 8200
+ # for an example
+ try:
+ self.processName = mp.current_process().name
+ except StandardError:
+ pass
if logProcesses and hasattr(os, 'getpid'):
self.process = os.getpid()
else: