
Hi Mark,
Le mar. 24 mars 2020 à 21:05, Mark Shannon mark@hotpy.org a écrit :
A native thread can only have one Python thread at a time, and must switch using the PyThreadState_Swap() API.
Right.
So, I think the answer is yes.
Nice.
Do you have a specific example or testcase?
I don't know well the C API of subinterpreters. Usually, I look at _testcapi.run_in_subinterp(). This function is used by multiple unit tests checking the behavior of subinterpreters.
--
My expectation is that the different ways to get the current Python thread state works as expected.
PyThreadState *tstate = PyThreadState_Get(); /* PyThreadState_GET() is an alias to PyThreadState_Get() */ PyThreadState *tstate = _PyThreadState_GET();
I also expect that tstate->interp is the current interpreter.
What is the behavior when the GIL is released? Is tstate equal to NULL when the GIL is released?
--
The less clear part is the PyGILState API:
PyThreadState *tstate = PyGILState_GetThisThreadState();
Does it return the current Pyhon thread state and is tstate->interp the current interpreter?
Victor