gh-121058: Warn if `PyThreadState_Clear` is called with an exception set (gh-121343)

This commit is contained in:
Peter Bierma 2024-11-20 12:27:19 -05:00 committed by GitHub
parent aea0c586d1
commit 6c1a4fb6d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View File

@ -0,0 +1,2 @@
``PyThreadState_Clear()`` now warns (and calls ``sys.excepthook``) if the
thread state still has an active exception.

View File

@ -1649,6 +1649,11 @@ PyThreadState_Clear(PyThreadState *tstate)
"PyThreadState_Clear: warning: thread still has a frame\n");
}
if (verbose && tstate->current_exception != NULL) {
fprintf(stderr, "PyThreadState_Clear: warning: thread has an exception set\n");
_PyErr_Print(tstate);
}
/* At this point tstate shouldn't be used any more,
neither to run Python code nor for other uses.