[New-bugs-announce] [issue43768] Possible race condition on multiprocessing.Manager().dict() on macOS

Jerry Chen report at bugs.python.org
Wed Apr 7 15:12:33 EDT 2021

New submission from Jerry Chen <jerryc443 at gmail.com>:

I am not sure if this is a bug or an expected case.

Long story short, I tried to print the content of a `multiprocessing.Manager().dict()` in the main thread, but I got a strange error.

I encountered this error only when the number of pools is rather large (>20) and only on `macOS` (works perfectly on `Linux`).

  CPU: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
macOS: 11.2.3

The minimum err code is attached:
#!/usr/bin/env python3

from contextlib import suppress
import multiprocessing as mp
import time

def run():
    D[mp.current_process().name] = 'some val'

if __name__ == '__main__':
    D, rets = mp.Manager().dict(), []
    with mp.Pool(25) as p:
        for _ in range(33):
        while rets:
            for ret in rets[:]:
                with suppress(mp.TimeoutError):


Traceback (most recent call last):
  File "/usr/local/Cellar/python at 3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/managers.py", line 801, in _callmethod
    conn = self._tls.connection
AttributeError: 'ForkAwareLocal' object has no attribute 'connection'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python at 3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/Users/???", line 9, in run
    D[mp.current_process().name] = 'some val'
  File "<string>", line 2, in __setitem__
  File "/usr/local/Cellar/python at 3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/managers.py", line 805, in _callmethod
  File "/usr/local/Cellar/python at 3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/managers.py", line 792, in _connect
    conn = self._Client(self._token.address, authkey=self._authkey)
  File "/usr/local/Cellar/python at 3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/connection.py", line 507, in Client
    c = SocketClient(address)
  File "/usr/local/Cellar/python at 3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/connection.py", line 635, in SocketClient
ConnectionRefusedError: [Errno 61] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/???", line 22, in <module>
  File "/usr/local/Cellar/python at 3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 771, in get
    raise self._value
ConnectionRefusedError: [Errno 61] Connection refused

components: macOS
messages: 390468
nosy: jerryc443, ned.deily, ronaldoussoren
priority: normal
severity: normal
status: open
title: Possible race condition on multiprocessing.Manager().dict() on macOS
type: behavior
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list