how to run python script with os.fork on windows?
There is no easy way to emulate fork()
on systems that don't have it, such as Windows. If the code only uses fork()
to start a new process with exec
, you can port it to use subprocess
. But this doesn't appear to be the case in rq, so you have several options:
Port
rq
to Windows, or ask someone to do it for you. The easiest way to port the part of the code that callsfork()
might be by using themultiprocessing
module. However, you will still need to replace other parts of the code that depend on Unix, such as uses ofsignal.alarm()
in thetimeouts
module.Use Python under Cygwin, which emulates a fully functional (though slowish)
fork()
, so Cygwin Python has a workingos.fork()
. Note that to getos.fork()
, you will need to use a Cygwin-built Python, such as the one that Cygwin ships, and not simply run the normal Windows Python under Cygwin.Test the application on a Linux running in a virtual machine.
Among these unhappy options I'd recommend the last one.
On windows, you can install cygwin with python. This python installation will have os module which will support os.fork() call.
Import a wrapper that conditionally wraps the appropriate subprocess call in a function called fork and adds it to os namespace.
Possibly it may be an option to contact the vendor and point out that os.fork is not a preferred option for you.