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

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


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.