gen: Adapt to py38 CancelledError changes by bdarnell · Pull Request #2683 · tornadoweb/tornado · GitHub
Skip to content

gen: Adapt to py38 CancelledError changes - #2683

Merged
bdarnell merged 3 commits into
tornadoweb:masterfrom
bdarnell:cancelledexception-py38
Jun 22, 2019
Merged

bdarnell merged 3 commits into
tornadoweb:masterfrom
bdarnell:cancelledexception-py38

Conversation

@bdarnell

Copy link
Copy Markdown
Member

python/cpython#13528 broke us in two ways: asyncio.CancelledError is
no longer an alias for concurrent.futures.CancelledError and it's now
a BaseException.

Fixes #2677
Closes #2681

cc @1st1

Comment thread tornado/gen.py Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should always be quiet. If a developer wants to log them in some task, they can always explicitly catch CancelledErrors, log, and then immediately re-raise them.

Maybe a better (and backwards/forward) compatible code here would be this:

try:
  future.result()
except asyncio.CancelledError:
  raise
except Exception:
  ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path is for when an exception is raised after the original caller is no longer present (because of a timeout). There's nowhere else for someone to catch exceptions that make it here. All we can do is log it or not.

Tornado has an uneasy relationship with cancellation, since we never supported it until it started creeping in accidentally with asyncio integration. I still tend to think of it as weird and exceptional (because tornado will never cancel anything), but maybe that's the wrong way to look at it and we should just make CancelledError always quiet here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path is for when an exception is raised after the original caller is no longer present (because of a timeout).

Got it. I think making them quiet is the right thing to do. After a timeout there is no useful information that a logged CancelledError can provide.

CancelledError is now always considered "quiet" (and
concurrent.futures.CancelledError is no longer the same as
asyncio.CancelledError).
@bdarnell
bdarnell force-pushed the cancelledexception-py38 branch from 06f74e6 to 26a8f76 Compare June 22, 2019 13:42
@bdarnell

Copy link
Copy Markdown
Member Author

@bdarnell
bdarnell force-pushed the cancelledexception-py38 branch from 26a8f76 to 4d2b625 Compare June 22, 2019 13:55
Mark CancelledError change as 6.0.3
@bdarnell
bdarnell merged commit 1723df1 into tornadoweb:master Jun 22, 2019
@bdarnell
bdarnell deleted the cancelledexception-py38 branch June 22, 2019 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix python 3.8 CI

2 participants