-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
bpo-31033: Make traceback for cancelled asyncio tasks more useful #19951
Conversation
936548a
to
ba37fb2
Compare
94a8291
to
b89ddef
Compare
This moves (and renames) exc_state_clear() in genobject.c to _PyErr_ClearExcState() in pycore_pyerrors.h.
This simplifies calling _PyErr_ChainExceptions() when we want to set a _PyErr_StackItem as the exception context.
When an asyncio.Task is cancelled, the exception traceback now starts with where the task was first interrupted. Previously, the traceback only had "depth one."
cf2561f
to
e4cfc90
Compare
@1st1 Here's a new version of the PR after rebasing with PR #19979 and ensuring that the cancelled message isn't duplicated multiple times in the traceback. I'll show you what the output looks like in a comment after this. I wasn't able to get the tests passing using a weakref or setting Lines 360 to 363 in aa92a7c
Similarly, setting self._cancelled_exc to None wasn't working in certain tests for different reasons.
Can this be an optimization that's considered later? |
Here's an example to show you what the output look like. For this code: import asyncio, sys
async def nested():
fut = asyncio.sleep(1)
await fut # AWAIT #1
async def run():
task = asyncio.create_task(nested())
await asyncio.sleep(0)
task.cancel('POSSIBLY LONG CANCEL MESSAGE')
await task # AWAIT #2
loop = asyncio.new_event_loop()
try:
loop.run_until_complete(run())
finally:
loop.close() Here is before the PR:
And here is after the PR:
|
Okay, I was able to get it working with setting |
@1st1 Is there any way this can be merged by tomorrow? I addressed your first review comment (setting |
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.
Chris, this looks good and the usability improvement is huge. I've left a nit comment, feel free to address it in this PR or later, up to you. Thanks!
@ambv I think this needs to be included in 3.9. I'm going to merge it myself tomorrow morning if Chris doesn't. Or you can merge it as is! |
_PyErr_ChainStackItem was just added in pythonGH-19951 (for bpo-31033).
…H-19951) When an asyncio.Task is cancelled, the exception traceback now starts with where the task was first interrupted. Previously, the traceback only had "depth one."
_PyErr_ChainStackItem was just added in pythonGH-19951 (for bpo-31033).
When an asyncio.Task is cancelled, the exception traceback now starts with where the task was first interrupted.
Previously, the traceback only had "depth one," which wasn't too useful.
https://bugs.python.org/issue31033