Why multiprocessing.Process behave differently on windows and linux for global object and function arguments

On Linux (and other Unix-like OSs), Python’s multiprocessing module using fork() to create new child processes that efficiently inherit a copy of the parent process’s memory state. That means the interpreter doesn’t need to pickle the objects that are being passed as the Process‘s args since the child process will already have them available in their normal form.

Windows doesn’t have a fork() system call however, so the multiprocessing module needs to do a bit more work to make the child-spawning process work. The fork()-based implementation came first, and the non-forking Windows implementation came later.

It’s worth noting that the Python developers had often felt it was a bit of a misfeature for the creation of child processes to differ so much based on the platform you’re running Python on. So in Python 3.4, a new system was added to allow you to select the start method that you would prefer to use. The options are "fork", "forkserver" and "spawn". The "fork" method remains the default on Unix-like systems (where it was the only implementation in earlier versions of Python). The "spawn" method is the default (and only) option on Windows, but now can be used on Unix-like systems too. The "forkserver" method is sort of a hybrid between the two (and only available on some Unix-like systems). You can read more about the differences between the methods in the documentation.

Leave a Comment