[Python-checkins] cpython (merge 3.4 -> default): (Merge 3.4) Issue #21247: Fix a race condition in test_send_signal() of asyncio
victor.stinner
python-checkins at python.org
Thu Jul 17 23:51:19 CEST 2014
http://hg.python.org/cpython/rev/45e8eb53edbc
changeset: 91722:45e8eb53edbc
parent: 91720:2176496951a4
parent: 91721:651475d67225
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Jul 17 23:49:40 2014 +0200
summary:
(Merge 3.4) Issue #21247: Fix a race condition in test_send_signal() of asyncio
Add a basic synchronization mechanism to wait until the child process is ready
before sending it a signal.
files:
Lib/test/test_asyncio/test_subprocess.py | 19 +++++++++--
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -108,11 +108,22 @@
@unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
def test_send_signal(self):
- args = PROGRAM_BLOCKED
- create = asyncio.create_subprocess_exec(*args, loop=self.loop)
+ code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
+ args = [sys.executable, '-c', code]
+ create = asyncio.create_subprocess_exec(*args, loop=self.loop, stdout=subprocess.PIPE)
proc = self.loop.run_until_complete(create)
- proc.send_signal(signal.SIGHUP)
- returncode = self.loop.run_until_complete(proc.wait())
+
+ @asyncio.coroutine
+ def send_signal(proc):
+ # basic synchronization to wait until the program is sleeping
+ line = yield from proc.stdout.readline()
+ self.assertEqual(line, b'sleeping\n')
+
+ proc.send_signal(signal.SIGHUP)
+ returncode = (yield from proc.wait())
+ return returncode
+
+ returncode = self.loop.run_until_complete(send_signal(proc))
self.assertEqual(-signal.SIGHUP, returncode)
def prepare_broken_pipe_test(self):
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list