Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 212994e

Browse files
committed
Issue #23140, asyncio: Simplify the unit test
1 parent c447ba0 commit 212994e

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Lib/test/test_asyncio/test_subprocess.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,19 @@ def len_message(message):
226226
def test_cancel_process_wait(self):
227227
# Issue #23140: cancel Process.wait()
228228

229-
@asyncio.coroutine
230-
def wait_proc(proc, event):
231-
event.set()
232-
yield from proc.wait()
233-
234229
@asyncio.coroutine
235230
def cancel_wait():
236231
proc = yield from asyncio.create_subprocess_exec(
237232
*PROGRAM_BLOCKED,
238233
loop=self.loop)
239234

240235
# Create an internal future waiting on the process exit
241-
event = asyncio.Event(loop=self.loop)
242-
task = self.loop.create_task(wait_proc(proc, event))
243-
yield from event.wait()
236+
task = self.loop.create_task(proc.wait())
237+
self.loop.call_soon(task.cancel)
238+
try:
239+
yield from task
240+
except asyncio.CancelledError:
241+
pass
244242

245243
# Cancel the future
246244
task.cancel()

0 commit comments

Comments
 (0)