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
Simplify context manager in os.popen #56174
Comments
Previous to 3.2, os.popen was made a context manager thanks to a private helper, os._wrap_close (contextlib.closing was maybe unavailable due to a bootstrapping issue). Now that subprocess.Popen directly implements the context manager protocol, this could be cleaned up. |
Have you seen the comment on top of it? It says "Helper for popen() -- a proxy for a file whose close waits for the process". |
I'm pretty sure that the os._wrap_close wrapper is not the same thing as the Popen context manager. I don't think it's useful to try refactor this. As Antoine points out, the current wrapper serves a very different purpose. |
Looks like I’ve misunderstood and there is no duplication. If you feel sure about it, please reject and close this report. |
After bpo-12044, subprocess.Popen.__exit__ waits for process completion and closes streams. Doesn’t that make wrap_close obsolete? |
So is _wrap_close obsolete or not? |
Mark: if you know Python you can answer that question yourself by reading the code of the subprocess and os modules. From a fairly short glance at the code I'd say that _wrap_close is not obsolete. It is a wrapper about a file object for the stdout or stdin stream of a Popen object (depending on the last argument of os.popen), and when _wrap_close.close is called it closes the wrapped stream, then waits for the subprocess to die and returns a *transformation* of the exitcode attribute. If my interpretation of the _wrap_close is correct this issue can be closed as invalid (the code cannot be cleaned up without changing functionality) |
Closing this issue; I agree with Ronald's assessment. |
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: