More on Cygwin Python for Windows
As mentioned, the os.fork call is present in the Cygwin version of Python on Windows.
Even though this call is missing in the standard version of Python for Windows, you
can fork processes on Windows with Python if you install and use Cygwin. However,
the Cygwin fork call is not as efficient and does not work exactly the same as a fork on
true Unix systems.
Cygwin is a free, open source package which includes a library that attempts to provide
a Unix-like API for use on Windows machines, along with a set of command-line tools
that implement a Unix-like environment. It makes it easier to apply Unix skills and
code on Windows computers.
According to its FAQ documentation, though, “Cygwin fork() essentially works like a
noncopy on write version of fork() (like old Unix versions used to do). Because of this
it can be a little slow. In most cases, you are better off using the spawn family of calls
if possible.” Since this book’s fork examples don’t need to care about performance,
Cygwin’s fork suffices.
In addition to the fork call, Cygwin provides other Unix tools that would otherwise not
be available on all flavors of Windows, including os.mkfifo (discussed later in this
chapter). It also comes with a gcc compiler environment for building C extensions for
Python on Windows that will be familiar to Unix developers. As long as you’re willing
to use Cygwin libraries to build your application and power your Python, it’s very close
to Unix on Windows.
Like all third-party libraries, though, Cygwin adds an extra dependency to your sys-
tems. Perhaps more critically, Cygwin currently uses the GNU GPL license, which adds
distribution requirements beyond those of standard Python. Unlike using Python itself,
shipping a program that uses Cygwin libraries may require that your program’s source
code be made freely available (though RedHat offers a “buy-out” option which can
relieve you of this requirement). Note that this is a complex legal issue, and you should
study Cygwin’s license on your own if this may impact your programs. Its license does,
however, impose more constraints than Python’s (Python uses a “BSD”-style license,
not the GPL).
Despite licensing issue, Cygwin still can be a great way to get Unix-like functionality
on Windows without installing a completely different operating system such as
Linux—a more complete but generally more complex option. For more details, see
http://cygwin.com or run a search for Cygwin on the Web.
See also the standard library’s multiprocessing module and os.spawn family of calls,
covered later in this chapter, for alternative way to start parallel tasks and programs on
Unix and Windows that do not require fork and exec calls. To run a simple function
call in parallel on Windows (rather than on an external program), also see the section
on standard library threads later in this chapter. Threads, multiprocessing, and
os.spawn calls work on Windows in standard Python.
Forking Processes | 185