This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amy20_z
Recipients amy20_z
Date 2008-10-27.23:57:44
SpamBayes Score 1.5326629e-13
Marked as misclassified No
Message-id <>
I have a simple program to call a shell command "service cpboot start"
to start Check Point firewall on RHEL5.1.

#!/usr/bin/env python
# vim: softtabstop=4 shiftwidth=4 expandtab

import os
from subprocess import *

p = Popen('service cpboot stop',shell=True, stdout=PIPE)
output = p.communicate()
print 'STDERR: %s' % output[0]
print 'STDOUT: %s' % output[1]


Python process pid 13343 spawned child 13375 to run "service cpboot
start".  However, after child process 13375 finished and sent SIGCHLD to
the python script, the parent hangs in Popen function communicate() at
line 1041 and child process 13375 became a defunct process.

Traceback (most recent call last):
  File "./", line 7, in ?
    output = p.communicate()
  File "/usr/lib/python2.4/", line 1041, in communicate
    rlist, wlist, xlist =, write_set, [])

Here is part of the strace:

Process 13375 detached
[pid 19195] close(878)                  = -1 EBADF (Bad file descriptor)
[pid 19195] close(879)                  = -1 EBADF (Bad file descriptor)
[pid 19195] close(880)                  = -1 EBADF (Bad file descriptor)
[pid 13343] <... select resumed> )      = ? ERESTARTNOHAND (To be restarted)
[pid 19195] close(881 <unfinished ...>
[pid 13343] --- SIGCHLD (Child exited) @ 0 (0) ---
[pid 19195] <... close resumed> )       = -1 EBADF (Bad file descriptor)
[pid 13343] select(7, [4 6], [], [], NULL <unfinished ...>

It seems like the select system call got interrupted and error code was
"ERESTARTNOHAND" was returned. The PIPEs won't be able to terminate
since child process has finished and exited and EOF won't be read from
the PIPEs.

If executing the shell command directly from shell command line, there's
no problem at all.It seems like there might be some race condition
somewhere in the python library. 

Any idea what may cause the problem? Many thanks in advance.
Date User Action Args
2008-10-27 23:57:47amy20_zsetrecipients: + amy20_z
2008-10-27 23:57:47amy20_zsetmessageid: <>
2008-10-27 23:57:46amy20_zlinkissue4216 messages
2008-10-27 23:57:45amy20_zcreate