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.

classification
Title: Simplify context manager in os.popen
Type: Stage: needs patch
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, akuchling, eric.araujo, offby1, pitrou, ronaldoussoren
Priority: normal Keywords: easy

Created on 2011-04-30 15:49 by eric.araujo, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg134870 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-04-30 15:49
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.
msg134921 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-05-01 19:21
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".
msg135202 - (view) Author: Chris Rose (offby1) * Date: 2011-05-05 13:58
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.
msg135212 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-05-05 15:39
Looks like I’ve misunderstood and there is no duplication.  If you feel sure about it, please reject and close this report.
msg135905 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-05-13 13:17
After #12044, subprocess.Popen.__exit__ waits for process completion and closes streams.  Doesn’t that make wrap_close obsolete?
msg185568 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2013-03-30 15:30
So is _wrap_close obsolete or not?
msg190177 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-05-28 06:53
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)
msg202284 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2013-11-06 19:47
Closing this issue; I agree with Ronald's assessment.
History
Date User Action Args
2022-04-11 14:57:16adminsetgithub: 56174
2013-11-06 19:47:54akuchlingsetstatus: open -> closed

nosy: + akuchling
messages: + msg202284

resolution: not a bug
2013-05-28 06:53:27ronaldoussorensetnosy: + ronaldoussoren

messages: + msg190177
versions: + Python 3.4, - Python 3.2
2013-03-30 15:30:57BreamoreBoysetnosy: + BreamoreBoy
messages: + msg185568
2011-05-13 13:17:11eric.araujosetmessages: + msg135905
2011-05-05 15:39:04eric.araujosetmessages: + msg135212
2011-05-05 13:58:06offby1setnosy: + offby1
messages: + msg135202
2011-05-01 19:21:28pitrousetnosy: + pitrou
messages: + msg134921
2011-04-30 15:49:30eric.araujocreate