File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed
Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,8 @@ PyAPI_FUNC(void) _PyRuntime_Finalize(void);
269269#define _Py_CURRENTLY_FINALIZING (runtime , tstate ) \
270270 (runtime->finalizing == tstate)
271271
272+ PyAPI_FUNC (int ) _Py_IsMainInterpreter (PyThreadState * tstate );
273+
272274
273275/* Variable and macro for in-line access to current thread
274276 and interpreter state */
Original file line number Diff line number Diff line change @@ -1466,9 +1466,9 @@ static PyObject *
14661466_thread__is_main_interpreter_impl (PyObject * module )
14671467/*[clinic end generated code: output=7dd82e1728339adc input=cc1eb00fd4598915]*/
14681468{
1469- _PyRuntimeState * runtime = & _PyRuntime ;
1470- PyInterpreterState * interp = _PyRuntimeState_GetThreadState ( runtime ) -> interp ;
1471- return PyBool_FromLong (interp == runtime -> interpreters . main );
1469+ PyThreadState * tstate = _PyThreadState_GET () ;
1470+ int is_main = _Py_IsMainInterpreter ( tstate ) ;
1471+ return PyBool_FromLong (is_main );
14721472}
14731473
14741474static PyMethodDef thread_methods [] = {
Original file line number Diff line number Diff line change @@ -159,6 +159,12 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
159159#define HEAD_UNLOCK (runtime ) \
160160 PyThread_release_lock((runtime)->interpreters.mutex)
161161
162+ int
163+ _Py_IsMainInterpreter (PyThreadState * tstate )
164+ {
165+ return (tstate -> interp == tstate -> interp -> runtime -> interpreters .main );
166+ }
167+
162168/* Forward declaration */
163169static void _PyGILState_NoteThreadState (
164170 struct _gilstate_runtime_state * gilstate , PyThreadState * tstate );
You can’t perform that action at this time.
0 commit comments