[Python-checkins] r87757 - python/branches/py3k/Lib/test/test_threading.py

victor.stinner python-checkins at python.org
Wed Jan 5 04:54:28 CET 2011


Author: victor.stinner
Date: Wed Jan  5 04:54:28 2011
New Revision: 87757

Log:
test_threading: use Popen.communicate() instead of .wait()

Popen.communicate() avoids deadlocks and close the pipes when done. This commit
fixes a ResourceWarning(unclosed pipe).

Modified:
   python/branches/py3k/Lib/test/test_threading.py

Modified: python/branches/py3k/Lib/test/test_threading.py
==============================================================================
--- python/branches/py3k/Lib/test/test_threading.py	(original)
+++ python/branches/py3k/Lib/test/test_threading.py	Wed Jan  5 04:54:28 2011
@@ -512,9 +512,9 @@
     def assertScriptHasOutput(self, script, expected_output):
         p = subprocess.Popen([sys.executable, "-c", script],
                              stdout=subprocess.PIPE)
-        rc = p.wait()
-        data = p.stdout.read().decode().replace('\r', '')
-        self.assertEqual(rc, 0, "Unexpected error")
+        stdout, stderr = p.communicate()
+        data = stdout.decode().replace('\r', '')
+        self.assertEqual(p.returncode, 0, "Unexpected error")
         self.assertEqual(data, expected_output)
 
     @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()")


More information about the Python-checkins mailing list