New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subprocess.Popen hangs at communicate() when child exits #48466
Comments
I have a simple program to call a shell command "service cpboot start" ================= 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 Traceback (most recent call last):
File "./subprocess_test03.py", line 7, in ?
output = p.communicate()
File "/usr/lib/python2.4/subprocess.py", line 1041, in communicate
rlist, wlist, xlist = select.select(read_set, write_set, [])
KeyboardInterrupt Here is part of the strace: Process 13375 detached It seems like the select system call got interrupted and error code was If executing the shell command directly from shell command line, there's Any idea what may cause the problem? Many thanks in advance. |
I'm unable to reproduce your problem with Python 2.4.4 nor Python Your problem is specific to the command "service cpboot start"? You Can you attach the full trace? I mean something like "strace -f -o |
Yes, I can only replicate this issue with command to start firewall. Somehow select system call is interrupted and can't terminate the PIPE. I'll collect the full log and attach it here. |
The bug should be fixed in Python 2.5 since it uses: while read_set or write_set:
try:
rlist, wlist, xlist = select.select(read_set, write_set,
[])
except select.error, e:
if e[0] == errno.EINTR:
continue
else:
raise EINTR is supported in subprocess for select(), read(), write() and Can't you migrate to Python 2.5 or 2.6? You can try to copy |
I'm running python 2.5.2 on Ubuntu 8.10. I believe I've also encountered the problem reported here. The scenario
Analysis: The reason for this is that process C (ssh) gets its stdout and stderr The set of conditions which will trigger the effect is not outlandish. In my case, I fixed the problem by changing the code of process B to (FYI, process A in my case is the python testing tool nosetests. I use It seems that in general subprocess creators might have two needs:
Currently, need 1 is addressed by communicate() but not need 2. In my |
I think communicate() works as documented now: reads stdout/stderr You're asking for a different method, or perhaps an optional I think this is more a feature request than a crash, targeted to |
Yes I think subprocess is working correctly. Since this feature request is 2 years old now without any interest, I think it should be closed. If the functionality is needed, it can always be programmed by the user when needed. |
You can try subprocess.call() with close_fds=True. |
Closing as suggested by Ross |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: