Skip to content

Commit 6c1a4fb

Browse files
gh-121058: Warn if PyThreadState_Clear is called with an exception set (gh-121343)
1 parent aea0c58 commit 6c1a4fb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``PyThreadState_Clear()`` now warns (and calls ``sys.excepthook``) if the
2+
thread state still has an active exception.

Python/pystate.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,11 @@ PyThreadState_Clear(PyThreadState *tstate)
16491649
"PyThreadState_Clear: warning: thread still has a frame\n");
16501650
}
16511651

1652+
if (verbose && tstate->current_exception != NULL) {
1653+
fprintf(stderr, "PyThreadState_Clear: warning: thread has an exception set\n");
1654+
_PyErr_Print(tstate);
1655+
}
1656+
16521657
/* At this point tstate shouldn't be used any more,
16531658
neither to run Python code nor for other uses.
16541659

0 commit comments

Comments
 (0)