Problems with background processes on Windows

Tim Roberts timr at
Sat Mar 28 07:19:10 CET 2009

geoff.bache at wrote:
>The following code behaves differently on Windows and Linux using
>Python 2.5.2. The Linux behaviour is what I expect in both places :)
>Perhaps somebody could help explain this. Or maybe it is a Python bug.
>Or a Windows feature...
>On Windows if I run "" it does not return for 10
>seconds, i.e. until the "grandchild" background process terminates. On
>Linux it returns immediately as I would expect.
>If I replace "p.communicate()" with "p.wait()" it returns immediately
>on both. If I don't point stdin, stdout and stderr of the child
>process to os.devnull then it will wait 10 seconds on Linux also,
>which I'd also expect as we can't collect info from these places if
>they've been forwarded elsewhere. It seems like Windows somehow
>doesn't notice this.

If you trace through this:
    python -m trace --trace

you'll see that it hangs in subprocess in the stdout_thread waiting for
stdout to close.

I'm not sure I expect this to work as you expect.  When you open a null
device, it's just another file handle.  Why should the behavior be
Tim Roberts, timr at
Providenza & Boekelheide, Inc.

More information about the Python-list mailing list