Skip to content

bpo-46771: Implement asyncio context managers for handling timeouts #31394

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

Merged
merged 31 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dac5874
bpo-46771: Implement asyncio context managers for handling timeouts
asvetlov Mar 2, 2022
374ff2a
Add reschedule tests
asvetlov Mar 2, 2022
70fa59b
Add reschedule tests
asvetlov Mar 2, 2022
3ae2af6
Dro breakpoint
asvetlov Mar 2, 2022
1654ec4
Tune repr
asvetlov Mar 2, 2022
2c9dbf8
Add tests
asvetlov Mar 2, 2022
baa7400
More tests
asvetlov Mar 2, 2022
1ca0fb8
Rename
asvetlov Mar 2, 2022
8a81dd1
Update Lib/asyncio/timeouts.py
asvetlov Mar 8, 2022
fae235d
Update Lib/asyncio/timeouts.py
asvetlov Mar 8, 2022
663b82f
Update Lib/asyncio/timeouts.py
asvetlov Mar 8, 2022
24d62d1
Update Lib/asyncio/timeouts.py
asvetlov Mar 8, 2022
6a26d1b
Add a test
asvetlov Mar 8, 2022
930b92b
Polish docstrings
asvetlov Mar 8, 2022
ac5c53d
Format
asvetlov Mar 8, 2022
f96ad1c
Tune tests
asvetlov Mar 8, 2022
94b4b4c
Fix comment
asvetlov Mar 8, 2022
388c6da
Tune comment
asvetlov Mar 8, 2022
cdc7f88
Tune docstrings
asvetlov Mar 8, 2022
9949fe4
Tune
asvetlov Mar 8, 2022
c716856
Tune tests
asvetlov Mar 8, 2022
b4889a0
Update Lib/test/test_asyncio/test_timeouts.py
asvetlov Mar 8, 2022
b6504e6
Tune tests
asvetlov Mar 8, 2022
fd2688d
Don't clobber foreign exceptions even if timeout is expiring
gvanrossum Mar 9, 2022
2ddda69
Add test from discussion
gvanrossum Mar 9, 2022
493545a
Fix indent of added test
gvanrossum Mar 9, 2022
ff36f2a
Disable slow callback warning
asvetlov Mar 9, 2022
8790e49
Reformat
asvetlov Mar 9, 2022
ac6f8c8
Increase delay
asvetlov Mar 9, 2022
e8c67ce
Don't raise TimeoutError if the CancelledError was swallowed by inner…
asvetlov Mar 9, 2022
e65d766
Don't duplicate py/c tests, timeout has no C accelerators
asvetlov Mar 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't clobber foreign exceptions even if timeout is expiring
(Includes test.)
  • Loading branch information
gvanrossum authored and asvetlov committed Mar 9, 2022
commit fd2688da3c7817659b76bb7c1c0fa44ee99ef973
3 changes: 2 additions & 1 deletion Lib/asyncio/timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import final, Optional, Type

from . import events
from . import exceptions
from . import tasks


Expand Down Expand Up @@ -91,7 +92,7 @@ async def __aexit__(
if self._state is _State.EXPIRING:
self._state = _State.EXPIRED

if self._task.uncancel() == 0:
if self._task.uncancel() == 0 and exc_type in (None, exceptions.CancelledError):
# Since there are no outstanding cancel requests, we're
# handling this.
raise TimeoutError
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_asyncio/test_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ async def test_foreign_exception_passed(self):
raise KeyError
self.assertFalse(cm.expired())

async def test_foreign_exception_on_timeout(self):
async def crash():
try:
await asyncio.sleep(1)
finally:
1/0
with self.assertRaises(ZeroDivisionError):
async with asyncio.timeout(0.01):
await crash()
async def test_foreign_cancel_doesnt_timeout_if_not_expired(self):
with self.assertRaises(asyncio.CancelledError):
async with asyncio.timeout(10) as cm:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy