mirror of
https://github.com/python/cpython.git
synced 2025-10-22 06:32:43 +00:00
Issue #23140, asyncio: Simplify the unit test
This commit is contained in:
parent
c447ba04e7
commit
212994e4e2
1 changed files with 6 additions and 8 deletions
|
@ -226,11 +226,6 @@ class SubprocessMixin:
|
||||||
def test_cancel_process_wait(self):
|
def test_cancel_process_wait(self):
|
||||||
# Issue #23140: cancel Process.wait()
|
# Issue #23140: cancel Process.wait()
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def wait_proc(proc, event):
|
|
||||||
event.set()
|
|
||||||
yield from proc.wait()
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def cancel_wait():
|
def cancel_wait():
|
||||||
proc = yield from asyncio.create_subprocess_exec(
|
proc = yield from asyncio.create_subprocess_exec(
|
||||||
|
@ -238,9 +233,12 @@ class SubprocessMixin:
|
||||||
loop=self.loop)
|
loop=self.loop)
|
||||||
|
|
||||||
# Create an internal future waiting on the process exit
|
# Create an internal future waiting on the process exit
|
||||||
event = asyncio.Event(loop=self.loop)
|
task = self.loop.create_task(proc.wait())
|
||||||
task = self.loop.create_task(wait_proc(proc, event))
|
self.loop.call_soon(task.cancel)
|
||||||
yield from event.wait()
|
try:
|
||||||
|
yield from task
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Cancel the future
|
# Cancel the future
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue