What's the best way to duplicate fork() in windows?

How do I implement some logic that will allow me to reproduce on Windows the functionality that I have on Linux with the fork() system call, using Python?

I'm specifically trying to execute a method on the SAPI Com component, while continuing the other logic in the main thread without blocking or waiting.


Solution 1:

Use the python multiprocessing module which will work everywhere.

Here is a IBM developerWords article that shows how to convert from os.fork() to the multiprocessing module.

Solution 2:

fork() has in fact been duplicated in Windows, under Cygwin, but it's pretty hairy.

The fork call in Cygwin is particularly interesting because it does not map well on top of the Win32 API. This makes it very difficult to implement correctly.

See the The Cygwin User's Guide for a description of this hack.

Solution 3:

Have a look at the process management functions in the os module. There are function for starting new processes in many different ways, both synchronously and asynchronously.

I should note also that Windows doesn't provide functionality that is exactly like fork() on other systems. To do multiprocessing on Windows, you will need to use the threading module.