[Python-Dev] [Python-checkins] r85987 - python/branches/py3k/Lib/test/test_os.py
Hirokazu Yamamoto
ocean-city at m2.ccsnet.ne.jp
Mon Nov 1 17:10:32 CET 2010
On 2010/10/31 6:24, brian.curtin wrote:
> Author: brian.curtin
> Date: Sat Oct 30 23:24:21 2010
> New Revision: 85987
>
> Log:
> Fix #10257. Clear resource warnings by using os.popen's context manager.
>
>
> Modified:
> python/branches/py3k/Lib/test/test_os.py
>
> Modified: python/branches/py3k/Lib/test/test_os.py
> ==============================================================================
> --- python/branches/py3k/Lib/test/test_os.py (original)
> +++ python/branches/py3k/Lib/test/test_os.py Sat Oct 30 23:24:21 2010
> @@ -406,17 +406,19 @@
> os.environ.clear()
> if os.path.exists("/bin/sh"):
> os.environ.update(HELLO="World")
> - value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
> - self.assertEquals(value, "World")
> + with os.popen("/bin/sh -c 'echo $HELLO'") as popen:
> + value = popen.read().strip()
> + self.assertEquals(value, "World")
Does this really cause resource warning? I think os.popen instance
won't be into traceback because it's not declared as variable. So I
suppose it will be deleted by reference count == 0 even when exception
occurs.
More information about the Python-Dev
mailing list