Skip to content

Commit 63b9772

Browse files
committed
Improve error message for a NULL tstate on the free-threaded build.
1 parent 26ff32b commit 63b9772

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Include/internal/pycore_pystate.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,17 @@ static inline void
190190
_Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
191191
{
192192
if (tstate == NULL) {
193+
#ifndef Py_GIL_DISABLED
193194
_Py_FatalErrorFunc(func,
194195
"the function must be called with the GIL held, "
195196
"after Python initialization and before Python finalization, "
196197
"but the GIL is released (the current Python thread state is NULL)");
198+
#else
199+
_Py_FatalErrorFunc(func,
200+
"the function must be called with an active thread state, "
201+
"after Python initialization and before Python finalization, but it is NULL "
202+
"(are you trying to call the C API inside of a Py_BEGIN_ALLOW_THREADS block?)");
203+
#endif
197204
}
198205
}
199206

0 commit comments

Comments
 (0)