@@ -56,6 +56,24 @@ _get_current_module(void)
56
56
}
57
57
58
58
59
+ static int
60
+ is_running_main (PyInterpreterState * interp )
61
+ {
62
+ if (_PyInterpreterState_IsRunningMain (interp )) {
63
+ return 1 ;
64
+ }
65
+ // Unlike with the general C-API, we can be confident that someone
66
+ // using this module for the main interpreter is doing so through
67
+ // the main program. Thus we can make this extra check. This benefits
68
+ // applications that embed Python but haven't been updated yet
69
+ // to call_PyInterpreterState_SetRunningMain().
70
+ if (_Py_IsMainInterpreter (interp )) {
71
+ return 1 ;
72
+ }
73
+ return 0 ;
74
+ }
75
+
76
+
59
77
/* Cross-interpreter Buffer Views *******************************************/
60
78
61
79
// XXX Release when the original interpreter is destroyed.
@@ -509,7 +527,7 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
509
527
// Ensure the interpreter isn't running.
510
528
/* XXX We *could* support destroying a running interpreter but
511
529
aren't going to worry about it for now. */
512
- if (_PyInterpreterState_IsRunningMain (interp )) {
530
+ if (is_running_main (interp )) {
513
531
PyErr_Format (PyExc_RuntimeError , "interpreter running" );
514
532
return NULL ;
515
533
}
@@ -977,7 +995,7 @@ interp_is_running(PyObject *self, PyObject *args, PyObject *kwds)
977
995
if (interp == NULL ) {
978
996
return NULL ;
979
997
}
980
- if (_PyInterpreterState_IsRunningMain (interp )) {
998
+ if (is_running_main (interp )) {
981
999
Py_RETURN_TRUE ;
982
1000
}
983
1001
Py_RETURN_FALSE ;
0 commit comments