Calling os.waitpid() From Secondary Thread Under Linux 2.2.12-20?
jon at dgs.monash.edu.au
Wed Apr 12 02:50:52 EDT 2000
Randy Wiser declared:
>I've written a small python program that spawns one child process from
>its main thread, and then creates a second thread. The sole purpose
>of the second thread (at this point) is to call os.waitpid(processID,
>0) to wait for the child that the main thread created. This works
>fine under Solaris when I call os.waitpid() from the second thread.
>But, under Linux 2.2.12-20 I get the following OSError exception:
>[Errno 10] No child processes
I recently had this reported as a problem in code I developed on a Sun,
which was then run on Linux. I believe it is due to Linux threads being
separate processes, hence the second thread is not the spawned process's
parent and cannot wait for it. (Presumably, if pthread_join() works, then
waitpid() should be able to work too, since they must be the same function
Anyway, my (non-)solution was to redesign my code to wait from the same
thread as the fork(). If you can't move the waitpid() into the main thread,
maybe you can move the fork() into the second thread.
More information about the Python-list