Skip to content

Passes through asyncio.CancelledError in tornado.gen.coroutine#3539

Open
AshwinDeshpandeBG wants to merge 2 commits intotornadoweb:masterfrom
berkshiregrey:feature/passthrough_asyncio_cancellederror
Open

Passes through asyncio.CancelledError in tornado.gen.coroutine#3539
AshwinDeshpandeBG wants to merge 2 commits intotornadoweb:masterfrom
berkshiregrey:feature/passthrough_asyncio_cancellederror

Conversation

@AshwinDeshpandeBG
Copy link
Copy Markdown

@AshwinDeshpandeBG AshwinDeshpandeBG commented Aug 28, 2025

If a tornado.coroutine raises an asyncio.CancelledError, it is handled badly as an asyncio.CancelledError is not an Exception, but there is no special logic in the tornado.coroutine to handle this BaseException. We suspect this bug was created in python 3.8 when asyncio.CancelledError changed from an Exception to a BaseException.

See bug report: #3537

@bdarnell
Copy link
Copy Markdown
Member

Hmm, is f.set_exception(CancelledError) equivalent to f.cancel()? I imagine they're slightly different because f.cancelled() would return false, but I'm not sure if it matters. We might need a separate branch in the try/except for CancelledError.

Or maybe we should be catching all errors (bare except: or except BaseException). That's what we do in some other places (see #3581) and I think the same logic might apply here.

@bdarnell bdarnell added the gen label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants