Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-121058: Warn if PyThreadState_Clear is called with an exception set #121343

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1687,6 +1687,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
Loading