Skip to content

Commit

Permalink
gh-121058: Warn if PyThreadState_Clear is called with an exception …
Browse files Browse the repository at this point in the history
…set (gh-121343)
  • Loading branch information
ZeroIntensity authored Nov 20, 2024
1 parent aea0c58 commit 6c1a4fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``PyThreadState_Clear()`` now warns (and calls ``sys.excepthook``) if the
thread state still has an active exception.
5 changes: 5 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6c1a4fb

Please sign in to comment.