◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
9 changes: 7 additions & 2 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,13 @@ async def wait_for(fut, timeout, *, loop=None):
if fut.done():
return fut.result()

fut.cancel()
raise exceptions.TimeoutError()

waiter = loop.create_future()
timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
Expand Down
31 changes: 31 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,9 @@ async def inner():
nonlocal task_done
try:
await asyncio.sleep(0.2)
finally:
task_done = True

Expand All @@ -900,6 +903,34 @@ async def inner():

loop.run_until_complete(foo())

def test_wait_for_self_cancellation(self):
loop = asyncio.new_event_loop()
self.addCleanup(loop.close)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Toggle all file notes Toggle all file annotations