New submission from Chang Zhou <quattroz...@gmail.com>:
Very first multiprocessing example not working on Windows 11 https://docs.python.org/3/library/multiprocessing.html from multiprocessing import Pool def f(x): return x*x if __name__ == '__main__': with Pool(5) as p: print(p.map(f, [1, 2, 3])) Tried Python 3.7, 3.8, 3.9, 3.10 Also tried Ubuntu which works fine. But on Windows (clean installed python): >>> from multiprocessing import Pool >>> def f(x): ... return x*x ... >>> with Pool(5) as p: ... print(p.map(f, [1, 2, 3])) ... Process SpawnPoolWorker-14: Process SpawnPoolWorker-13: Traceback (most recent call last): Process SpawnPoolWorker-15: File "C:\Program Files\Python39\lib\multiprocessing\process.py", line 315, in _bootstrap self.run() Traceback (most recent call last): File "C:\Program Files\Python39\lib\multiprocessing\process.py", line 108, in run self._target(*self._args, **self._kwargs) File "C:\Program Files\Python39\lib\multiprocessing\process.py", line 315, in _bootstrap self.run() File "C:\Program Files\Python39\lib\multiprocessing\pool.py", line 114, in worker task = get() File "C:\Program Files\Python39\lib\multiprocessing\process.py", line 108, in run self._target(*self._args, **self._kwargs) File "C:\Program Files\Python39\lib\multiprocessing\queues.py", line 368, in get return _ForkingPickler.loads(res) File "C:\Program Files\Python39\lib\multiprocessing\pool.py", line 114, in worker task = get() AttributeError: Can't get attribute 'f' on <module '__main__' (built-in)> File "C:\Program Files\Python39\lib\multiprocessing\queues.py", line 368, in get return _ForkingPickler.loads(res) AttributeError: Can't get attribute 'f' on <module '__main__' (built-in)> Traceback (most recent call last): File "C:\Program Files\Python39\lib\multiprocessing\process.py", line 315, in _bootstrap self.run() File "C:\Program Files\Python39\lib\multiprocessing\process.py", line 108, in run self._target(*self._args, **self._kwargs) File "C:\Program Files\Python39\lib\multiprocessing\pool.py", line 114, in worker task = get() File "C:\Program Files\Python39\lib\multiprocessing\queues.py", line 368, in get return _ForkingPickler.loads(res) AttributeError: Can't get attribute 'f' on <module '__main__' (built-in)> ---------- components: Windows messages: 407186 nosy: paul.moore, quattrozhou, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: Very first multiprocessing example not working on Windows 11 type: crash versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45914> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com