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).
This commit is contained in:
Victor Stinner 2011-01-05 03:54:28 +00:00
parent 4b2b43d988
commit c932b65428
1 changed files with 3 additions and 3 deletions

View File

@ -512,9 +512,9 @@ class ThreadJoinOnShutdown(BaseTestCase):
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()")