threading, subprocesses and wait

G

Gal Diskin

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)

Thanks in advance,
Gals
 
G

Gal Diskin

Jean-Paul Calderone said:
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

Thanks for the quick answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,219
Latest member
KristieKoh

Latest Threads

Top