-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
work around the changes in 3.11, eg asyncio.TimeoutError is an OSError, and IsolatedAsyncioTestCase calls set_event_loop differently #6877
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f9c86b4
try fixing AioHTTPTestCase for 3.11
graingert 355dc8e
Update aiohttp/test_utils.py
graingert 37fa089
add the setUp/tearDown code back to 3.7
graingert e5789af
disambiguate asyncio.TimeoutError from OSError
graingert 74340cb
wrap real OSError asyncio.TimeoutErrors in a ClientOSError
graingert a776ee3
add changelog
graingert 37b892c
Apply formatting to the change note
webknjaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Work around the changes in 3.11, e.g. :py:class:`~asyncio.TimeoutError` is an :py:class:`OSError`, | ||
and :py:class:`~unittest.IsolatedAsyncioTestCase` calls :py:function:`~asyncio.set_event_loop` | ||
differently -- by :user:`graingert`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,12 +430,12 @@ def get_app(self) -> Application: | |
raise RuntimeError("Did you forget to define get_application()?") | ||
|
||
def setUp(self) -> None: | ||
try: | ||
self.loop = asyncio.get_running_loop() | ||
except RuntimeError: | ||
self.loop = asyncio.get_event_loop_policy().get_event_loop() | ||
Comment on lines
-435
to
-436
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. This bit needed to be recovered in aiohttp v3.8 to preserve the compatibility with Python 3.6: ef6a373. |
||
if not PY_38: | ||
asyncio.get_event_loop().run_until_complete(self.asyncSetUp()) | ||
|
||
self.loop.run_until_complete(self.setUpAsync()) | ||
async def asyncSetUp(self) -> None: | ||
self.loop = asyncio.get_running_loop() | ||
return await self.setUpAsync() | ||
|
||
async def setUpAsync(self) -> None: | ||
self.app = await self.get_application() | ||
|
@@ -445,7 +445,11 @@ async def setUpAsync(self) -> None: | |
await self.client.start_server() | ||
|
||
def tearDown(self) -> None: | ||
self.loop.run_until_complete(self.tearDownAsync()) | ||
if not PY_38: | ||
self.loop.run_until_complete(self.asyncTearDown()) | ||
|
||
async def asyncTearDown(self) -> None: | ||
return await self.tearDownAsync() | ||
|
||
async def tearDownAsync(self) -> None: | ||
await self.client.close() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you explain the
is None
check? Is it just a performance optimization? Why'd you drop the separate block idea?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.
So this is for the case when you get a real OSError with an errno that's also a TimeoutError
I thought about checking for
type(TimeoutError.__cause__) is CancelledError
but your timeout context manager doesn't set the cause and neither does_chain_future
Then to my dismay if you do:
You still get a
TimeoutError
with aNone
.errno
so there's no way to actually tell if you have a real operating systemTimeoutError
or a synthetic one from asyncioThis is why trio uses
trio.TooSlowError
so it's a bit more clearThere 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.
Maybe worth checking if
asyncio.timeout()
has the same problem. We could start migrating from async-timeout to that in Python 3.11+.https://docs.python.org/3.11/library/asyncio-task.html#timeouts
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.
Would be good if we can all agree on some
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.
Ah, it still uses the same logic from async-timeout:
https://github.com/python/cpython/blob/main/Lib/asyncio/timeouts.py#L98
You'd have to take that up with the cpython issue tracker, or @asvetlov.
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.
python/cpython#95830
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.
So, if that gets merged, what does the code here become (assuming we've switched away from async-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.
Fixing _chain_future needs to happen first, but we can check the
__cause__
to see if it's an asyncio Timeout rather than an OS timeoutThere 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.
Just coming back round to this, I see the change is now in Python 3.12+. Can we update these checks with a sys.version_info check, so we don't forget about it completely?