-
-
Notifications
You must be signed in to change notification settings - Fork 726
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
implement wait_for using asyncio.timeout() on 3.11 #7571
implement wait_for using asyncio.timeout() on 3.11 #7571
Conversation
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 24 files ±0 24 suites ±0 10h 29m 33s ⏱️ - 5m 3s Results for commit 85dcc7b. ± Comparison against base commit 790d852. ♻️ This comment has been updated with latest results. |
ce86475
to
31f105c
Compare
…fusion with utils.wait_for
using asyncio.wait_for in utils_test.gen_test.<locals>.async_fn_outer spawns a new child task which has the extra effect of waiting an `await asyncio.sleep(0)` after every test before running utils_test.check_instances. When using `async with asyncio.timeout(t):` only the `asyncio.current_task()` is used and so this extra sleep is removed. This extra sleep is enough for the `CommClosedError` to be raised in the `test_listen_connect(_ws).<locals>.handle_comm` task. I proved this by checking that both test_listen_connect and test_listen_connect_wss both pass after restoring `asyncio.wait_for` in `only utils_test.gen_test.<locals>.async_fn_outer` or adding `asyncio.sleep(0)` to the end of the tests.
31f105c
to
85dcc7b
Compare
if sys.version_info >= (3, 11): | ||
|
||
async def wait_for(fut: Awaitable[T], timeout: float) -> T: | ||
async with asyncio.timeout(timeout): | ||
return await fut | ||
|
||
else: | ||
|
||
async def wait_for(fut: Awaitable[T], timeout: float) -> T: | ||
return await asyncio.wait_for(fut, timeout) |
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.
Not a big deal but we also have a compatibility module with things like this
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.
LGTM. Let me know if you want to move it over to compatibility or not. I don't have a strong preference
Closes #7570
pre-commit run --all-files