From 825358ab80d0e17e287c1e36a91dece0a97cb219 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 22 Nov 2019 05:33:34 +0100 Subject: [PATCH] [WIP/RFC] multiprocessing: proxy: keep _manager after forking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes iterating over dicts: import multiprocessing as mp def run(d): for k in d: print(k) manager = mp.Manager() d = manager.dict({1: 2, 3: 4}) process = mp.Process(target=run, args=(d,)) process.start() process.join() With this fix: _callmethod __iter__ #PROXY (('__next__', 'send', 'throw', 'close'), Token(typeid='Iterator', address='/tmp/pymp-wfn3r3nd/listener-ze4ow_dl', id='7f12414ca130')) _callmethod __next__ #RETURN 1 1 _callmethod __next__ #RETURN 3 3 _callmethod __next__ #ERROR Without: _callmethod __iter__ #PROXY (('__next__', 'send', 'throw', 'close'), Token(typeid='Iterator', address='/tmp/pymp-uppzhf9p/listener-mvmwwxma', id='7f5b7b42da90')) Process Process-2: Traceback (most recent call last): File "…/pyenv/3.8.0/lib/python3.8/multiprocessing/process.py", line 313, in _bootstrap self.run() File "…/pyenv/3.8.0/lib/python3.8/multiprocessing/process.py", line 108, in run self._target(*self._args, **self._kwargs) File "t-mp.py", line 5, in run for k in d: File "", line 2, in __iter__ File "…/pyenv/3.8.0/lib/python3.8/multiprocessing/managers.py", line 842, in _callmethod proxytype = self._manager._registry[token.typeid][-1] AttributeError: 'NoneType' object has no attribute '_registry' The line is from when multiprocessing was added in e711cafab1, so I am probably missing something here? This PR is meant to get tests run with it, and of course for any feedback already. --- Lib/multiprocessing/managers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py index 1f9c2daa25d..a39efd7c09c 100644 --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -874,7 +874,6 @@ class BaseProxy(object): del tls.connection def _after_fork(self): - self._manager = None try: self._incref() except Exception as e: