Uh oh!
There was an error while loading. Please reload this page.
bpo-31033: Make traceback for cancelled asyncio tasks more useful - #19951
Conversation
936548a to
ba37fb2Compare94a8291 to
b89ddefCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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
e4cfc90Comparecjerdonek
commented
May 16, 2020
@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? |
cjerdonek
commented
May 16, 2020
Here's an example to show you what the output look like. For this code: importasyncio, sysasyncdefnested():
fut=asyncio.sleep(1)
awaitfut# AWAIT #1asyncdefrun():
task=asyncio.create_task(nested())
awaitasyncio.sleep(0)
task.cancel('POSSIBLY LONG CANCEL MESSAGE')
awaittask# AWAIT #2loop=asyncio.new_event_loop()
try:
loop.run_until_complete(run())
finally:
loop.close()Here is before the PR: And here is after the PR: |
cjerdonek
commented
May 16, 2020
Okay, I was able to get it working with setting |
cjerdonek
commented
May 17, 2020
@1st1 Is there any way this can be merged by tomorrow? I addressed your first review comment (setting |
Uh oh!
There was an error while loading. Please reload this page.
1st1
left a comment
There was a problem hiding this comment.
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!
1st1
commented
May 18, 2020
@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