LoginSignup
1
0

More than 1 year has passed since last update.

【Python】multiprocessingのManagerでEOFErrorが発生した時の対処法

Last updated at Posted at 2021-07-18

下記コードで動作テストしたらEOFErrorになった。環境はMacOS, Python3.8

test.py
from mutliprocessing import Manager

with Manager() as manager:
    pass
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  ...
  File "/Users/oooo/opt/anaconda3/lib/python3.8/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    with Manager() as manager:
    ....
  File "/Users/oooo/opt/anaconda3/lib/python3.8/multiprocessing/connection.py", line 383, in _recv
    raise EOFError
EOFError

原因

なんのことはなく、ただif __name__ == "__main__":を書いてなかっただけだった。

from mutliprocessing import Manager

if __name__ == "__main__":
    with Manager() as manager:
        pass

これですんなりエラーが消えた。ちゃんと使い方理解できてなかっただけだった🙄

参考元

multiprocessing.Manager() + cd leads to EOFError #890 - Github

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0