| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -24,6 +24,7 @@ | |
| from . import events | ||
| from . import exceptions | ||
| from . import futures | ||
| from . import timeouts | ||
| from .coroutines import _is_coroutine | ||
|
|
||
| # Helper to generate new task names | ||
| Expand Down Expand Up | @@ -442,62 +443,12 @@ async def wait_for(fut, timeout): | |
|
|
||
| This function is a coroutine. | ||
| """ | ||
| loop = events.get_running_loop() | ||
|
|
||
| if timeout is None: | ||
| return await fut | ||
|
|
||
| if timeout <= 0: | ||
| fut = ensure_future(fut, loop=loop) | ||
|
|
||
| if fut.done(): | ||
| return fut.result() | ||
|
|
||
| await _cancel_and_wait(fut, loop=loop) | ||
| try: | ||
| return fut.result() | ||
| except exceptions.CancelledError as exc: | ||
| raise exceptions.TimeoutError() from exc | ||
|
|
||
| waiter = loop.create_future() | ||
| timeout_handle = loop.call_later(timeout, _release_waiter, waiter) | ||
| cb = functools.partial(_release_waiter, waiter) | ||
|
|
||
| fut = ensure_future(fut, loop=loop) | ||
| fut.add_done_callback(cb) | ||
| async def inner(): | ||
| async with timeouts.timeout(timeout): | ||
| return await fut | ||
|
|
||
| try: | ||
| # wait until the future completes or the timeout | ||
| try: | ||
| await waiter | ||
| except exceptions.CancelledError: | ||
| if fut.done(): | ||
| return fut.result() | ||
| else: | ||
| fut.remove_done_callback(cb) | ||
| # We must ensure that the task is not running | ||
| # after wait_for() returns. | ||
| # See https://bugs.python.org/issue32751 | ||
| await _cancel_and_wait(fut, loop=loop) | ||
| raise | ||
|
|
||
| if fut.done(): | ||
| return fut.result() | ||
| else: | ||
| fut.remove_done_callback(cb) | ||
| # We must ensure that the task is not running | ||
| # after wait_for() returns. | ||
| # See https://bugs.python.org/issue32751 | ||
| await _cancel_and_wait(fut, loop=loop) | ||
| # In case task cancellation failed with some | ||
| # exception, we should re-raise it | ||
| # See https://bugs.python.org/issue40607 | ||
| try: | ||
| return fut.result() | ||
| except exceptions.CancelledError as exc: | ||
| raise exceptions.TimeoutError() from exc | ||
| finally: | ||
| timeout_handle.cancel() | ||
| return await create_task(inner()) | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI 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
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think it would be better to skip this create_task and delete the tests that fail
Sorry, something went wrong.
All reactions
|
||
|
|
||
|
|
||
| async def _wait(fs, timeout, return_when, loop): | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality@asvetlov I've been having a go at this branch in bf594bd
you need to special case None in asyncio.wait_for(
and then special case 0 in timeouts.timeout see https://gist.github.com/graingert/ea2546b23b32be5a4493a9a115db2eff#file-timeout_bug-py-L6
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.