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 quattrozhou
Recipients paul.moore, quattrozhou, steve.dower, tim.golden, zach.ware
Date 2021-11-28.04:37:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638074274.33.0.534994157782.issue45914@roundup.psfhosted.org>
In-reply-to
Content
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)>
History
Date User Action Args
2021-11-28 04:37:54quattrozhousetrecipients: + quattrozhou, paul.moore, tim.golden, zach.ware, steve.dower
2021-11-28 04:37:54quattrozhousetmessageid: <1638074274.33.0.534994157782.issue45914@roundup.psfhosted.org>
2021-11-28 04:37:54quattrozhoulinkissue45914 messages
2021-11-28 04:37:54quattrozhoucreate