Why does Python's multiprocessing module import __main__ when starting a new process on Windows?

前端 未结 1 1230
感情败类
感情败类 2020-11-27 05:07

I am playing around with a library for my beginner students, and I\'m using the multiprocessing module in Python. I ran into this problem: importing and using a module that

相关标签:
1条回答
  • 2020-11-27 05:28

    Windows doesn't have fork, so there's no way to make a new process just like the existing one. So the child process has to run your code again, but now you need a way to distinguish between the parent process and the child process, and __main__ is it.

    This is covered in the docs here: http://docs.python.org/2/library/multiprocessing.html#windows

    I don't know of another way to structure the code to avoid the fork bomb effect.

    0 讨论(0)
提交回复
热议问题