1

I got the error AttributeError: module 'multiprocessing.util' has no attribute '_args_from_interpreter_flags' when running a program of mine, which worked a while ago. Even with simple example code like

import multiprocessing as mp
def f(x):
    return x * x
if __name__ == '__main__':
    with mp.Pool(5) as p:
        print(p.map(f, [1, 2, 3]))

I get this error. Has anyone come across this, too?

Traceback (most recent call last):\
 File "C:/Users/.../AppData/Roaming/JetBrains/PyCharmCE2020.3/scratches/scratch.py", line 18, in <module> with mp.Pool(5) as p:\
 File "C:\Users\...\venv\lib\multiprocessing\context.py", 
  line 119, in Pool context=self.get_context())\
 File "C:\Users\...\venv\lib\multiprocessing\pool.py", line 
  176, in __init__ self._repopulate_pool()\
 File "C:\Users\...\venv\lib\multiprocessing\pool.py", line 
  241, in _repopulate_pool w.start()\
 File "C:\Users\...\venv\lib\multiprocessing\process.py", 
  line 112, in start self._popen = self._Popen(self)\
 File "C:\Users\...\venv\lib\multiprocessing\context.py", 
  line 322, in _Popen return Popen(process_obj)\
 File "C:\Users\...\venv\lib\multiprocessing\popen_spawn_win32.py", line 53, in __init__ pipe_handle=rhandle)\
 File "C:\Users\...\venv\lib\multiprocessing\spawn.py", line 88, in get_command_line opts = util._args_from_interpreter_flags()\
AttributeError: module 'multiprocessing.util' has no attribute '_args_from_interpreter_flags'

I am currently using Python 3.7.10 in Pycharm on Windows 10

tripleee
  • 175,061
  • 34
  • 275
  • 318
wit4
  • 19
  • 2
  • could you please provide the complete stack trace? – Stefan Paul Noack Oct 07 '21 at 09:07
  • 1
    What version of python are you using? What operating system are you using? – Daweo Oct 07 '21 at 09:07
  • You need to give us more details to go on. If you're using IPython see this answer: https://stackoverflow.com/a/65001152/1084416. Also, some people seem to have issues with Spyder and pdb (which I've never used). – Peter Wood Oct 07 '21 at 09:13
  • Your code, as presented in your question, works without error in Python 3.9.7. Do you perhaps have your own script called multiprocessing.py? –  Oct 07 '21 at 09:29
  • I had issues with it in spyder, wouldn't run if I just selected and ran the lines. Had to click the 'Run file' button, not great when you're trying to work out how things work! https://stackoverflow.com/questions/69219881/multiprocessing-errors – Emi OB Oct 07 '21 at 09:48
  • I've added more information to the problem description. I also don't find another file called multiprocessing.py – wit4 Oct 07 '21 at 11:36
  • Have you tried running this from a CMD window - i.e., not in PyCharm? –  Oct 07 '21 at 11:51
  • I haven't before. Just tested it. This is working fine. – wit4 Oct 07 '21 at 12:38
  • It is running when using the base environment, but not when using the environment of my project – wit4 Oct 07 '21 at 14:47

1 Answers1

0

I had the same error on a Mac with Python 3.9 in IPython, so I searched for a solution.

Fixed the issue by using multiprocess in place of multiprocessing as suggested in Multiprocessing example giving AttributeError. This now works just fine:

import multiprocess as mp
def f(x):
    return x * x

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

On the other hand, the original code (using the multiprocessing library) works when used in a script, so the issue seems to be of concern only for IPython (and Jupyter notebooks, I assume).

user2314737
  • 27,088
  • 20
  • 102
  • 114