8000 gh-128479: fix asyncio staggered race leaking tasks, and logging unhandled exception.append exception by graingert · Pull Request #128475 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128479: fix asyncio staggered race leaking tasks, and logging unhandled exception.append exception #128475

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
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
add test
  • Loading branch information
graingert committed Jan 4, 2025
commit 950187964fb6d29165f115a9b449a8f14d2e9494
27 changes: 27 additions & 0 deletions Lib/test/test_asyncio/test_staggered.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,30 @@ async def do_set():
self.assertIsNone(excs[0], None)
self.assertIsInstance(excs[1], asyncio.CancelledError)
self.assertIsInstance(excs[2], asyncio.CancelledError)


async def test_cancelled(self):
log = []
with self.assertRaises(TimeoutError):
async with asyncio.timeout(None) as cs_outer, asyncio.timeout(None) as cs_inner:
async def coro_fn():
cs_inner.reschedule(-1)
await asyncio.sleep(0)
try:
await asyncio.sleep(0)
except asyncio.CancelledError:
log.append("cancelled 1")

cs_outer.reschedule(-1)
await asyncio.sleep(0)
try:
await asyncio.sleep(0)
except asyncio.CancelledError:
log.append("cancelled 2")
try:
await staggered_race([coro_fn], delay=None)
except asyncio.CancelledError:
log.append("cancelled 3")
raise

self.assertListEqual(log, ["cancelled 1", "cancelled 2", "cancelled 3"])
Loading
0