-
-
Notifications
You must be signed in to change notification settings - Fork 30k
-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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'ed children hang due to open pipes #48362
Comments
subprocess.Popen.wait() hangs if you have spawned multiple child Here is a test program: import subprocess, sys
p1 = subprocess.Popen("cat", bufsize=0, stdin=subprocess.PIPE)
p2 = subprocess.Popen("cat", bufsize=0, stdin=subprocess.PIPE)
p1.stdin.close()
ret = p1.wait()
print >>sys.stderr, "Child 1 wait completed with ret", ret
p2.stdin.close()
ret = p2.wait()
print >>sys.stderr, "Child 2 wait completed with ret", ret, "Bye bye" The call to p1.wait() will never return. If p2.wait is called first, p1 never terminates because p1.stdin is duplicated in the (second) child I am not sure whether this is a bug or deliberate design, but the wait() will not hang if the "close on exec" flag is set on the elif stdin == PIPE: The last line is the added one, similar lines must be added for stdout Alternatively, the test program above will terminate cleanly if |
Would someone with knowledge of subprocess please comment on this. |
The suggestion looks reasonable to me, and the current behavior does not look like an intentional design. Boye, would you be interested in proposing a patch with unit tests? |
This issue has been fixed on 3.2. |
This has been fixed with all the subprocess improvements in between 3.1 and 3.2 but the decision has been taken (msg125910) not to backport the fix to 3.1 and 2.7 which would involve a C extension. However, a workaround on 2.7 and 3.1 is to set close_fds=True. Closing as "wont fix". |
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: