PyCharm 2023.2.3 Fails to Run Multiprocessing

Multiprocessing documentation gives a simple example of the use of Pool that I have broken into two separate files test.py and test_a.py

test.py is used to call the worker function in test_a.py

If I run test.py in the command line it works as expected but if I run this in PyCharm's Python Console then errors result in an endless loop until I stop the console. Below is the example code.

----------------------------------

test.py

----------------------------------

import test_a
from multiprocessing import Pool

if __name__ == '__main__':
    with Pool(5) as p:
        print(p.map(test_a.main, [1, 2, 3]))

 

----------------------------------

test_a.py

----------------------------------

def main(x):
    return x*x
 

----------------------------------

Errors

----------------------------------

Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "C:\Users\cc\anaconda3\envs\py311\Lib\multiprocessing\spawn.py", line 113, in spawn_main
Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "C:\Users\cc\anaconda3\envs\py311\Lib\multiprocessing\spawn.py", line 113, in spawn_main
   new_handle = reduction.duplicate(pipe_handle,
               new_handle = reduction.duplicate(pipe_handle,
           ^^ ^ ^   ^^ ^   ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^  File "C:\Users\cc\anaconda3\envs\py311\Lib\multiprocessing\reduction.py", line 79, in duplicate
^^^^^^^
 File "C:\Users\cc\anaconda3\envs\py311\Lib\multiprocessing\reduction.py", line 79, in duplicate
   return _winapi.DuplicateHandle(
     return _winapi.DuplicateHandle(  
                ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^PermissionError^^: [WinError 5] Access is denied
^^^^^
PermissionError: [WinError 5] Access is denied
Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "C:\Users\cc\anaconda3\envs\py311\Lib\multiprocessing\spawn.py", line 113, in spawn_main
   new_handle = reduction.duplicate(pipe_handle,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "C:\Users\cc\anaconda3\envs\py311\Lib\multiprocessing\reduction.py", line 79, in duplicate
   return _winapi.DuplicateHandle(
          ^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [WinError 5] Access is denied
Process finished with exit code 0

 

Is there a correct configuration for this process? Or is there a fix? Or is a downgrade a possible solution? Is there any solution?

0
2 comments

These errors occur when the code is ran as a selection.

0
Unfortunately, this is a known issue PY-36151 (https://youtrack.jetbrains.com/issue/PY-36151). Feel free to follow and comment, and sorry for the inconvenience.
0

Please sign in to leave a comment.