static PyInterpreterState * interp_look_up_id(PY_INT64_T requested_id) { PyInterpreterState *interp = PyInterpreterState_Head(); while (interp != NULL) { PY_INT64_T id = PyInterpreterState_GetID(interp); if (id < 0) { return NULL; } if (requested_id == id) { return interp; } interp = PyInterpreterState_Next(interp); } return NULL; }
static void print_subinterp(void) { /* Output information about the interpreter in the format expected in Lib/test/test_capi.py (test_subinterps). */ PyThreadState *ts = PyThreadState_Get(); PyInterpreterState *interp = ts->interp; int64_t id = PyInterpreterState_GetID(interp); printf("interp %" PRId64 " <0x%" PRIXPTR ">, thread state <0x%" PRIXPTR ">: ", id, (uintptr_t)interp, (uintptr_t)ts); fflush(stdout); PyRun_SimpleString( "import sys;" "print('id(modules) =', id(sys.modules));" "sys.stdout.flush()" ); }
PyInterpreterState * _PyInterpreterState_LookUpID(PY_INT64_T requested_id) { if (requested_id < 0) goto error; PyInterpreterState *interp = PyInterpreterState_Head(); while (interp != NULL) { PY_INT64_T id = PyInterpreterState_GetID(interp); if (id < 0) return NULL; if (requested_id == id) return interp; interp = PyInterpreterState_Next(interp); } error: PyErr_Format(PyExc_RuntimeError, "unrecognized interpreter ID %lld", requested_id); return NULL; }