-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Context management support for subprocess.Popen #54763
Comments
I propose that __enter__ and __exit__ be added to subprocess.Popen. __enter__ returns self, __exit__ closes open file descriptors. __exit__ could also do the same checks that __del__ does (and which I don’t entirely understand. See also os.popen (os._wrap_close). |
Here's a patch which implements the context manager and adds a few tests and a small doc change. Tested on Mac and Windows. |
Thanks! Patch looks good, tests pass and doc builds. I have one question and two micro-nitpicks on http://codereview.appspot.com/3441041/ |
I updated the doc to be much more simple. I got used to sys.executable based tests :) New patch attached. As for __del__, I think it should do it's thing, and the exit will do it's own. Context managers are traditionally used on file-based things, or things that can be opened or closed. Creating a Popen object will open one or more pipes, so we should just close those opened pipes. |
New doc looks good. Suggested changes: make with a link, explaing why it’s a context manager.
I agree with your view on __del__ vs. __exit__. |
:keyword:`with`` → :keyword:`with` |
Committed in r86951. Thanks for the reviews! |
“closing any open file descriptors on exit” is exactly the perfect wording I was looking for. Thanks for the patch! |
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: