Multiprocessing question

Steven D'Aprano steve+comp.lang.python at
Mon Jul 14 04:44:16 CEST 2014

On Sun, 13 Jul 2014 19:53:09 -0400, Paul LaFollette wrote:

> I have thrown together a little C/UNIX program that forks a child
> process, then proceeds to let the child and parent alternate.  Either
> can run until it pauses itself and wakes the other.
> I would like to know if there be a way to create the same behavior in
> Python 3, preferably in a non-platform dependent fashion.

The most direct way of duplicating the Unix idiom of forking a child 
process is to use the os.fork function, which is (I believe) just a thin 
wrapper around the C fork function.

But this is not platform-independent, it is Unix only.

Alternatively, you can look at the various os.exec* functions, which are 
available on Windows and Unix, and see if any of them are useful.

But the best way to solve this in a platform independent way is to use 
one of the concurrency modules:

such as multiprocessing. Although these are written for Python 2 rather 
than 3, you may find them useful:


More information about the Python-list mailing list