]> granicus.if.org Git - python/commitdiff
Issue #23140, asyncio: Simplify the unit test
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 6 Jan 2015 00:22:45 +0000 (01:22 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 6 Jan 2015 00:22:45 +0000 (01:22 +0100)
Lib/test/test_asyncio/test_subprocess.py

index dfe23be24a5d868870426d60fc918a0388181deb..1fe9095d16568f286a0d3fbf93802e3e5ed8df34 100644 (file)
@@ -226,11 +226,6 @@ class SubprocessMixin:
     def test_cancel_process_wait(self):
         # Issue #23140: cancel Process.wait()
 
-        @asyncio.coroutine
-        def wait_proc(proc, event):
-            event.set()
-            yield from proc.wait()
-
         @asyncio.coroutine
         def cancel_wait():
             proc = yield from asyncio.create_subprocess_exec(
@@ -238,9 +233,12 @@ class SubprocessMixin:
                                           loop=self.loop)
 
             # Create an internal future waiting on the process exit
-            event = asyncio.Event(loop=self.loop)
-            task = self.loop.create_task(wait_proc(proc, event))
-            yield from event.wait()
+            task = self.loop.create_task(proc.wait())
+            self.loop.call_soon(task.cancel)
+            try:
+                yield from task
+            except asyncio.CancelledError:
+                pass
 
             # Cancel the future
             task.cancel()