From da742ba826721da84140abc785856d4ccc2d787f Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sun, 17 May 2020 22:47:31 -0700 Subject: bpo-31033: Improve the traceback for cancelled asyncio tasks (GH-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." --- Python/errors.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index f856a798ee..3b42c1120b 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -512,6 +512,20 @@ _PyErr_ChainExceptions(PyObject *exc, PyObject *val, PyObject *tb) } } +void +_PyErr_ChainStackItem(_PyErr_StackItem *exc_state) +{ + if (exc_state->exc_type == NULL || exc_state->exc_type == Py_None) { + return; + } + Py_INCREF(exc_state->exc_type); + Py_XINCREF(exc_state->exc_value); + Py_XINCREF(exc_state->exc_traceback); + _PyErr_ChainExceptions(exc_state->exc_type, + exc_state->exc_value, + exc_state->exc_traceback); +} + static PyObject * _PyErr_FormatVFromCause(PyThreadState *tstate, PyObject *exception, const char *format, va_list vargs) -- cgit v1.2.1