threading, subprocesses and wait

Jean-Paul Calderone exarkun at divmod.com
Tue Sep 26 15:49:11 CEST 2006


On 26 Sep 2006 06:29:17 -0700, Gal Diskin <gal.diskin at gmail.com> wrote:
>Hi all,
>I'm writing a python program using threads to open several subprocesses
>concurrently (using module subprocess) and wait on them. I was
>wondering if there is a possibilty that a thread will return from wait
>even though the subprocess that finished was created by another thread
>thats also waiting.
>
>i.e. - 2 threads, each thread opens a subprocess and waits. The
>subprocess created by thread 1 has ended and thread 2 is released from
>wait instead of thread 1. Is this scenario possible? (I have reason to
>believe this has happend to me, but it seems unreasonable behaviour)

>From a superficial reading of the code, it looks like this should not
happen.  The wait call uses waitpid(2) which will only return when the
specified pid has terminated.

On the other hand, it performs no error handling at all, so if the SIGCHLD
for thread 1's process is delivered to thread 2, it may cause the wait call
to fail with an EINTR OSError.  Whether this is actually possible or not
depends on what signal handlers, if any, have been installed, as well as the
underlying C and threading libraries, though.

Jean-Paul



More information about the Python-list mailing list