@@ -2547,37 +2547,34 @@ _PyThread_CurrentFrames(void)
25472547 return NULL ;
25482548 }
25492549
2550- /* for i in all interpreters:
2551- * for t in all of i's thread states:
2552- * if t's frame isn't NULL, map t's id to its frame
2550+ /* for t in all of the current interpreter's thread states:
2551+ * if t's frame isn't NULL, map t's id to its frame
25532552 * Because these lists can mutate even when the GIL is held, we
25542553 * need to grab head_mutex for the duration.
25552554 */
2556- _PyEval_StopTheWorldAll (runtime );
2555+ PyInterpreterState * interp = tstate -> interp ;
2556+ _PyEval_StopTheWorld (interp );
25572557 HEAD_LOCK (runtime );
2558- PyInterpreterState * i ;
2559- for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
2560- PyThreadState * t ;
2561- for (t = i -> threads .head ; t != NULL ; t = t -> next ) {
2562- _PyInterpreterFrame * frame = t -> current_frame ;
2563- frame = _PyFrame_GetFirstComplete (frame );
2564- if (frame == NULL ) {
2565- continue ;
2566- }
2567- PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2568- if (id == NULL ) {
2569- goto fail ;
2570- }
2571- PyObject * frameobj = (PyObject * )_PyFrame_GetFrameObject (frame );
2572- if (frameobj == NULL ) {
2573- Py_DECREF (id );
2574- goto fail ;
2575- }
2576- int stat = PyDict_SetItem (result , id , frameobj );
2558+ PyThreadState * t ;
2559+ for (t = interp -> threads .head ; t != NULL ; t = t -> next ) {
2560+ _PyInterpreterFrame * frame = t -> current_frame ;
2561+ frame = _PyFrame_GetFirstComplete (frame );
2562+ if (frame == NULL ) {
2563+ continue ;
2564+ }
2565+ PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2566+ if (id == NULL ) {
2567+ goto fail ;
2568+ }
2569+ PyObject * frameobj = (PyObject * )_PyFrame_GetFrameObject (frame );
2570+ if (frameobj == NULL ) {
25772571 Py_DECREF (id );
2578- if (stat < 0 ) {
2579- goto fail ;
2580- }
2572+ goto fail ;
2573+ }
2574+ int stat = PyDict_SetItem (result , id , frameobj );
2575+ Py_DECREF (id );
2576+ if (stat < 0 ) {
2577+ goto fail ;
25812578 }
25822579 }
25832580 goto done ;
@@ -2587,7 +2584,7 @@ _PyThread_CurrentFrames(void)
25872584
25882585done :
25892586 HEAD_UNLOCK (runtime );
2590- _PyEval_StartTheWorldAll ( runtime );
2587+ _PyEval_StartTheWorld ( interp );
25912588 return result ;
25922589}
25932590
@@ -2613,36 +2610,33 @@ _PyThread_CurrentExceptions(void)
26132610 return NULL ;
26142611 }
26152612
2616- /* for i in all interpreters:
2617- * for t in all of i's thread states:
2618- * if t's frame isn't NULL, map t's id to its frame
2613+ /* for t in all of the current interpreter's thread states:
2614+ * if t's frame isn't NULL, map t's id to its exception
26192615 * Because these lists can mutate even when the GIL is held, we
26202616 * need to grab head_mutex for the duration.
26212617 */
2622- _PyEval_StopTheWorldAll (runtime );
2618+ PyInterpreterState * interp = tstate -> interp ;
2619+ _PyEval_StopTheWorld (interp );
26232620 HEAD_LOCK (runtime );
2624- PyInterpreterState * i ;
2625- for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
2626- PyThreadState * t ;
2627- for (t = i -> threads .head ; t != NULL ; t = t -> next ) {
2628- _PyErr_StackItem * err_info = _PyErr_GetTopmostException (t );
2629- if (err_info == NULL ) {
2630- continue ;
2631- }
2632- PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2633- if (id == NULL ) {
2634- goto fail ;
2635- }
2636- PyObject * exc = err_info -> exc_value ;
2637- assert (exc == NULL ||
2638- exc == Py_None ||
2639- PyExceptionInstance_Check (exc ));
2640-
2641- int stat = PyDict_SetItem (result , id , exc == NULL ? Py_None : exc );
2642- Py_DECREF (id );
2643- if (stat < 0 ) {
2644- goto fail ;
2645- }
2621+ PyThreadState * t ;
2622+ for (t = interp -> threads .head ; t != NULL ; t = t -> next ) {
2623+ _PyErr_StackItem * err_info = _PyErr_GetTopmostException (t );
2624+ if (err_info == NULL ) {
2625+ continue ;
2626+ }
2627+ PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2628+ if (id == NULL ) {
2629+ goto fail ;
2630+ }
2631+ PyObject * exc = err_info -> exc_value ;
2632+ assert (exc == NULL ||
2633+ exc == Py_None ||
2634+ PyExceptionInstance_Check (exc ));
2635+
2636+ int stat = PyDict_SetItem (result , id , exc == NULL ? Py_None : exc );
2637+ Py_DECREF (id );
2638+ if (stat < 0 ) {
2639+ goto fail ;
26462640 }
26472641 }
26482642 goto done ;
@@ -2652,7 +2646,7 @@ _PyThread_CurrentExceptions(void)
26522646
26532647done :
26542648 HEAD_UNLOCK (runtime );
2655- _PyEval_StartTheWorldAll ( runtime );
2649+ _PyEval_StartTheWorld ( interp );
26562650 return result ;
26572651}
26582652
0 commit comments