Issue 11965: Simplify context manager in os.popen (original) (raw)

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:16 admin set github: 56174
2013-11-06 19:47:54 akuchling set status: open -> closednosy: + akuchlingmessages: + resolution: not a bug
2013-05-28 06:53:27 ronaldoussoren set nosy: + ronaldoussorenmessages: + versions: + Python 3.4, - Python 3.2
2013-03-30 15:30:57 BreamoreBoy set nosy: + BreamoreBoymessages: +
2011-05-13 13:17:11 eric.araujo set messages: +
2011-05-05 15:39:04 eric.araujo set messages: +
2011-05-05 13:58:06 offby1 set nosy: + offby1messages: +
2011-05-01 19:21:28 pitrou set nosy: + pitroumessages: +
2011-04-30 15:49:30 eric.araujo create