Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No child processes" on os.waitpid

I'm trying to simulate behavior of os.system with Popen and waitpid on Ubuntu and I'm getting

OSError: [Errno 10] No child processes

here's how I'm using it

p = Popen(args, stdout = PIPE, stderr = PIPE)
stdout, stderr = p.communicate()
returncode = os.waitpid(p.pid, 0)[1]

I tried to get return code out of p.returncode , but it is always None, any ideas how to get the return code?

like image 820
Yaroslav Bulatov Avatar asked Oct 18 '25 11:10

Yaroslav Bulatov


1 Answers

communicate already waits on the child process to terminate, and collects the return code itself. Therefore, when you call os.waitpid, you're calling it referencing a process ID that has already been removed from the OS tables. Therefore, you get the "No child process" error.

The return code you're looking for will be stored in the returncode field of of the process object after communicate returns.

like image 84
tylerl Avatar answered Oct 21 '25 11:10

tylerl