-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Refactor asyncio.wait_for() #31847
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
Refactor asyncio.wait_for() #31847
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,12 +444,11 @@ async def wait_for(fut, timeout): | |
This function is a coroutine. | ||
""" | ||
|
||
if not futures.isfuture(fut): | ||
# wrap a coroutine | ||
fut = create_task(fut) | ||
async def inner(): | ||
async with timeouts.timeout(timeout): | ||
return await fut | ||
|
||
async with timeouts.timeout(timeout): | ||
return await fut | ||
return await create_task(inner()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this extra create_task is worth it, the tests it passes are equivalent to: async def wait_for(fut, delay):
if delay is None:
return await fut
if delay <= 0:
if asyncio.iscoroutine(fut):
fut.close()
raise TimeoutError There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to skip this create_task and delete the tests that fail |
||
|
||
|
||
async def _wait(fs, timeout, return_when, loop): | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asvetlov I've been having a go at this branch in bf594bd
you need to special case
None
inasyncio.wait_for(
and then special case
0
in timeouts.timeout see https://gist.github.com/graingert/ea2546b23b32be5a4493a9a115db2eff#file-timeout_bug-py-L6