Skip to content

Refactor asyncio.wait_for() - #31847

Closed
asvetlov wants to merge 4 commits into
mainfrom
refactor-wait_for
Closed

Refactor asyncio.wait_for()#31847
asvetlov wants to merge 4 commits into
mainfrom
refactor-wait_for

Conversation

@asvetlov

Copy link
Copy Markdown
Contributor

No description provided.

Comment threadLib/asyncio/tasks.py

fut = ensure_future(fut, loop=loop)
fut.add_done_callback(cb)
async def inner():

@graingertgraingertJul 20, 2022

Copy link
Copy Markdown
Contributor

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 in asyncio.wait_for(

Suggested change
asyncdefinner():
iftimeoutisNone:
returnawaitfut
asyncdefinner():

and then special case 0 in timeouts.timeout see https://gist.github.com/graingert/ea2546b23b32be5a4493a9a115db2eff#file-timeout_bug-py-L6

Comment threadLib/asyncio/tasks.py
raise exceptions.TimeoutError() from exc
finally:
timeout_handle.cancel()
return await create_task(inner())

@graingertgraingertJul 21, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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:

asyncdefwait_for(fut, delay):
ifdelayisNone:
returnawaitfutifdelay<=0:
ifasyncio.iscoroutine(fut):
fut.close()
raiseTimeoutError

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

@pablogsal
pablogsal deleted the refactor-wait_for branch December 14, 2022 20:34
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@asvetlov@graingert@pablogsal@the-knights-who-say-ni@ezio-melotti@bedevere-bot