This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kyle.smith
Recipients kyle.smith, steven.daprano
Date 2022-02-27.13:56:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645970169.65.0.942120138478.issue46871@roundup.psfhosted.org>
In-reply-to
Content
Interesting. I did try between MacOS (12.2) and Ubuntu since I have servers with older python versions. For scoping then, this appears to be related only to MacOS since you were able to confirm it working correctly on Linux. 

The code is the same, but here's the entire traceback. All below examples were run on MacOS:

bash-3.2$ python3 --version
Python 3.9.6
bash-3.2$ python3 main.py
Traceback (most recent call last):
  File "/Volumes/Workspace/co/router/main.py", line 21, in <module>
    shared_dict, shared_lock = get_shared_state(HOST, PORT, KEY)
  File "/Volumes/Workspace/co/router/main.py", line 12, in get_shared_state
    manager.start()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/managers.py", line 553, in start
    self._process.start()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'get_shared_state.<locals>.<lambda>'


Running this with 3.7.9 works:
bash-3.2$ python3.7 --version
Python 3.7.9
bash-3.2$ python3.7 main.py
{'number': 0, 'text': 'Hello World'}


If it's of interest, 3.10.2 is also failing on Mac.

bash-3.2$ /usr/local/opt/python\@3.10/bin/python3 --version
Python 3.10.2
bash-3.2$ /usr/local/opt/python\@3.10/bin/python3 main.py
Traceback (most recent call last):
  File "/Volumes/Workspace/co/router/main.py", line 21, in <module>
    shared_dict, shared_lock = get_shared_state(HOST, PORT, KEY)
  File "/Volumes/Workspace/co/router/main.py", line 12, in get_shared_state
    manager.start()
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/managers.py", line 562, in start
    self._process.start()
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'get_shared_state.<locals>.<lambda>'
History
Date User Action Args
2022-02-27 13:56:09kyle.smithsetrecipients: + kyle.smith, steven.daprano
2022-02-27 13:56:09kyle.smithsetmessageid: <1645970169.65.0.942120138478.issue46871@roundup.psfhosted.org>
2022-02-27 13:56:09kyle.smithlinkissue46871 messages
2022-02-27 13:56:09kyle.smithcreate