Multiprocessing launching too many instances of Python VM

It looks like you didn’t carefully follow the guidelines in the documentation, specifically this section where it talks about “Safe importing of main module”.

You need to protect your launch code with an if __name__ == '__main__': block or you’ll get what you’re getting, I believe.

I believe it comes down to the multiprocessing module not being able to use os.fork() as it does on Linux, where an already-running process is basically cloned in memory. On Windows (which has no such fork()) it must run a new Python interpreter and tell it to import your main module and then execute the start/run method once that’s done. If you have code at “module level”, unprotected by the name check, then during the import it starts the whole sequence over again, ad infinitum

Leave a Comment