mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-37658: Fix asyncio.wait_for() to respect waited task status (#21894)
Currently, if `asyncio.wait_for()` itself is cancelled it will always raise `CancelledError` regardless if the underlying task is still running. This is similar to a race with the timeout, which is handled already.
This commit is contained in:
parent
c517fc7121
commit
a2118a1462
3 changed files with 24 additions and 3 deletions
|
@ -1120,6 +1120,22 @@ class BaseTaskTests:
|
|||
res = loop.run_until_complete(task)
|
||||
self.assertEqual(res, "ok")
|
||||
|
||||
def test_wait_for_cancellation_race_condition(self):
|
||||
def gen():
|
||||
yield 0.1
|
||||
yield 0.1
|
||||
yield 0.1
|
||||
yield 0.1
|
||||
|
||||
loop = self.new_test_loop(gen)
|
||||
|
||||
fut = self.new_future(loop)
|
||||
loop.call_later(0.1, fut.set_result, "ok")
|
||||
task = loop.create_task(asyncio.wait_for(fut, timeout=1))
|
||||
loop.call_later(0.1, task.cancel)
|
||||
res = loop.run_until_complete(task)
|
||||
self.assertEqual(res, "ok")
|
||||
|
||||
def test_wait_for_waits_for_task_cancellation(self):
|
||||
loop = asyncio.new_event_loop()
|
||||
self.addCleanup(loop.close)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue