Skip to content

Commit

Permalink
task: Prevent error indicator being sporadically cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
rdb committed May 31, 2021
1 parent e63eab9 commit c9508f3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions panda/src/event/asyncFuture_ext.cxx
Expand Up @@ -398,6 +398,10 @@ PyObject *Extension<AsyncFuture>::
get_cancelled_error_type() {
static PyObject *exc_type = nullptr;
if (exc_type == nullptr) {
// This method should not affect the current exception, so stash it.
PyObject *curexc_type, *curexc_value, *curexc_traceback;
PyErr_Fetch(&curexc_type, &curexc_value, &curexc_traceback);

// Get the CancelledError that asyncio uses, too.
#if PY_VERSION_HEX >= 0x03080000
PyObject *module = PyImport_ImportModule("asyncio.exceptions");
Expand All @@ -408,9 +412,6 @@ get_cancelled_error_type() {
exc_type = PyObject_GetAttrString(module, "CancelledError");
Py_DECREF(module);
}
else {
PyErr_Clear();
}

// If we can't get that, we should pretend and make our own.
if (exc_type == nullptr) {
Expand All @@ -424,6 +425,8 @@ get_cancelled_error_type() {
nullptr, nullptr);
#endif
}

PyErr_Restore(curexc_type, curexc_value, curexc_traceback);
}
return exc_type;
}
Expand Down

0 comments on commit c9508f3

Please sign in to comment.