Skip to content

GH-96764: rewrite asyncio.wait_for to use asyncio.timeout #98518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
487eac1
rewrite wait_for to use timeouts.timeout
kumaraditya303 Sep 12, 2022
794cb3a
skip one test
kumaraditya303 Oct 21, 2022
13ab78f
fix test as wait_for no longer creates
kumaraditya303 Oct 21, 2022
1eb0053
remove outdated tests
kumaraditya303 Oct 21, 2022
c704996
fix future test
kumaraditya303 Oct 22, 2022
bdaed9d
more tests
kumaraditya303 Oct 22, 2022
8ec6b37
fix whitespaces and comment
kumaraditya303 Oct 22, 2022
b711aa1
📜🤖 Added by blurb_it.
blurb-it[bot] Oct 22, 2022
69c03b1
remove None special case
kumaraditya303 Oct 22, 2022
92df33b
Update Misc/NEWS.d/next/Library/2022-10-22-09-26-43.gh-issue-96764.Dh…
kumaraditya303 Oct 23, 2022
0290362
fix typo
kumaraditya303 Oct 24, 2022
4d3e9a3
remove a test
kumaraditya303 Oct 26, 2022
5fece55
fix comment
kumaraditya303 Nov 30, 2022
e7595a2
Merge branch 'main' of https://github.com/python/cpython into waitfor
kumaraditya303 Feb 12, 2023
9b0ef93
code review
kumaraditya303 Feb 12, 2023
c98ea70
add shield tests
kumaraditya303 Feb 12, 2023
8b54ce5
more comments
kumaraditya303 Feb 12, 2023
6d39219
whitespace
kumaraditya303 Feb 12, 2023
d7efdcb
typo
kumaraditya303 Feb 12, 2023
27cfdf9
formatting
kumaraditya303 Feb 12, 2023
979f07f
improve test
kumaraditya303 Feb 12, 2023
7a7082c
more comments
kumaraditya303 Feb 12, 2023
1239246
Update Lib/test/test_asyncio/test_waitfor.py
kumaraditya303 Feb 12, 2023
f0b5480
add back tasks.py changes, somehow got lost
kumaraditya303 Feb 12, 2023
355f2df
comments++
kumaraditya303 Feb 16, 2023
49d0ee4
fix typo
kumaraditya303 Feb 16, 2023
549b03f
remove wrong comment
kumaraditya303 Feb 16, 2023
56e6038
add code as explanantion
kumaraditya303 Feb 16, 2023
1a912f4
Update Lib/asyncio/tasks.py
kumaraditya303 Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
code review
  • Loading branch information
kumaraditya303 committed Feb 12, 2023
commit 9b0ef93407dd90359c1fc081e472705efc02f0f0
7 changes: 7 additions & 0 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,16 @@ async def wait_for(fut, timeout):

If the wait is cancelled, the task is also cancelled.

If the task supresses the cancellation and returns a value instead,
that value is returned.

This function is a coroutine.
"""

# When timeout <= 0, `asyncio.timeout` raises `TimeoutError`
# whereas `wait_for` disables the timeout so we special case
# it here to preserve the behavior.

if timeout is not None and timeout <= 0:
fut = ensure_future(fut)

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_asyncio/test_futures2.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ async def func():
return asyncio.all_tasks()

# The repr() call should not raise RecursionError at first.
repr(await asyncio.wait_for(func(), timeout=10))
waiter = await asyncio.wait_for(asyncio.Task(func()),timeout=10)
self.assertIn('...', repr(waiter))


if __name__ == '__main__':
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_asyncio/test_waitfor.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ async def test_cancel_wait_for(self):
await self._test_cancel_wait_for(60.0)

async def test_wait_for_cancel_suppressed(self):
# See https://github.com/python/cpython/issues/84849
# See https://github.com/python/cpython/pull/28149
# GH-86296: Supressing CancelledError is discouraged
# but if a task subpresses CancelledError and returns a value,
# `wait_for` should return the value instead of raising CancelledError.
# This is the same behavior as `asyncio.timeout`.

async def return_42():
try:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy