classification
Title: SystemError: Parent module 'multiprocessing' not loaded, cannot perform relative import
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: sbt Nosy List: Amr.Ali, brett.cannon, jnoller, python-dev, sbt
Priority: normal Keywords:

Created on 2014-02-15 08:08 by Amr.Ali, last changed 2014-03-23 17:23 by sbt. This issue is now closed.

Messages (3)
msg211262 - (view) Author: Amr Ali (Amr.Ali) Date: 2014-02-15 08:08
Using `multiprocessing.Manager` to share a `dict` between two processes raises the below exception at main process termination. Child process is joined and terminates gracefully before the main process.

Replacing multiprocessing/forking.py:135 with `from multiprocessing.connection import wait` fixes the issue.

Python 3.3.1 (default, Sep 25 2013, 19:29:01) 
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'3.3.1 (default, Sep 25 2013, 19:29:01) \n[GCC 4.7.3]'

# multiprocessing/forking.py:135

132         def wait(self, timeout=None):                                            
133             if self.returncode is None:                                          
134                 if timeout is not None:                                          
135                     from .connection import wait                                 
136                     if not wait([self.sentinel], timeout):                       
137                         return None                                              
138                 # This shouldn't block if wait() returned successfully.          
139                 return self.poll(os.WNOHANG if timeout == 0.0 else 0)            
140             return self.returncode                                               

# Traceback

Traceback (most recent call last):
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/util.py", line 255, in _run_finalizers
    finalizer()
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/util.py", line 188, in __call__
    res = self._callback(*self._args, **self._kwargs)
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/managers.py", line 588, in _finalize_manager
    process.join(timeout=1.0)
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/process.py", line 127, in join
    res = self._popen.wait(timeout)
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/forking.py", line 135, in wait
    from .connection import wait
SystemError: Parent module 'multiprocessing' not loaded, cannot perform relative import
Traceback (most recent call last):
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/util.py", line 255, in _run_finalizers
    finalizer()
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/util.py", line 188, in __call__
    res = self._callback(*self._args, **self._kwargs)
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/managers.py", line 588, in _finalize_manager
    process.join(timeout=1.0)
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/process.py", line 127, in join
    res = self._popen.wait(timeout)
  File "/home/d4de/work/redacted/redacted-engine/venv/lib/python3.3/multiprocessing/forking.py", line 135, in wait
    from .connection import wait
SystemError: Parent module 'multiprocessing' not loaded, cannot perform relative import
msg211264 - (view) Author: Amr Ali (Amr.Ali) Date: 2014-02-15 09:17
Also importing `multiprocessing.forking` at the very beginning of MyLib/__init__.py fixes the problem.
msg214573 - (view) Author: Roundup Robot (python-dev) Date: 2014-03-23 12:54
New changeset 0b2814fc53ae by Richard Oudkerk in branch '3.3':
Issue #20633: Replace relative import by absolute import.
http://hg.python.org/cpython/rev/0b2814fc53ae
History
Date User Action Args
2014-03-23 17:23:02sbtsetstatus: open -> closed
resolution: fixed
stage: resolved
2014-03-23 12:54:42python-devsetnosy: + python-dev
messages: + msg214573
2014-03-01 10:12:18sbtsetassignee: sbt
2014-02-15 09:17:52Amr.Alisetmessages: + msg211264
2014-02-15 08:45:12ezio.melottisetnosy: + brett.cannon
type: crash -> behavior
2014-02-15 08:08:12Amr.Alicreate