]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #8200: logging: Handle errors when multiprocessing is not fully loaded when...
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 22 Mar 2010 12:33:08 +0000 (12:33 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 22 Mar 2010 12:33:08 +0000 (12:33 +0000)
Lib/logging/__init__.py
Misc/NEWS

index b1810d68e53768641da06489140685a6f1c6faf6..088c1fc9ca0e29a1ea42c7a280f955f324f207b9 100644 (file)
@@ -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:
index dd61f4f64c2a56feed88ded45256d848801d381b..12db4af60fb3b57acd7c344159ca48dcaefd4ce0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #8200: logging: Handle errors when multiprocessing is not
+  fully loaded when logging occurs.
+
 - Issue #3890: Fix recv() and recv_into() on non-blocking SSL sockets.
 
 - Issue #8179: Fix macpath.realpath() on a non-existing path.