From 6c1a4fb6d400827155fd70e48d682e35397731a1 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Wed, 20 Nov 2024 12:27:19 -0500 Subject: gh-121058: Warn if `PyThreadState_Clear` is called with an exception set (gh-121343) --- Python/pystate.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index 01e54fc745d..44f55be5b5b 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -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. -- cgit v1.2.3