@@ -2725,36 +2725,33 @@ _PyThread_CurrentFrames(void)
27252725 return NULL ;
27262726 }
27272727
2728- /* for i in all interpreters:
2729- * for t in all of i's thread states:
2730- * if t's frame isn't NULL, map t's id to its frame
2728+ /* for t in all of the current interpreter's thread states:
2729+ * if t's frame isn't NULL, map t's id to its frame
27312730 * Because these lists can mutate even when the GIL is held, we
27322731 * need to grab head_mutex for the duration.
27332732 */
2734- _PyEval_StopTheWorldAll (runtime );
2733+ PyInterpreterState * interp = tstate -> interp ;
2734+ _PyEval_StopTheWorld (interp );
27352735 HEAD_LOCK (runtime );
2736- PyInterpreterState * i ;
2737- for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
2738- _Py_FOR_EACH_TSTATE_UNLOCKED (i , t ) {
2739- _PyInterpreterFrame * frame = t -> current_frame ;
2740- frame = _PyFrame_GetFirstComplete (frame );
2741- if (frame == NULL ) {
2742- continue ;
2743- }
2744- PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2745- if (id == NULL ) {
2746- goto fail ;
2747- }
2748- PyObject * frameobj = (PyObject * )_PyFrame_GetFrameObject (frame );
2749- if (frameobj == NULL ) {
2750- Py_DECREF (id );
2751- goto fail ;
2752- }
2753- int stat = PyDict_SetItem (result , id , frameobj );
2736+ _Py_FOR_EACH_TSTATE_UNLOCKED (interp , t ) {
2737+ _PyInterpreterFrame * frame = t -> current_frame ;
2738+ frame = _PyFrame_GetFirstComplete (frame );
2739+ if (frame == NULL ) {
2740+ continue ;
2741+ }
2742+ PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2743+ if (id == NULL ) {
2744+ goto fail ;
2745+ }
2746+ PyObject * frameobj = (PyObject * )_PyFrame_GetFrameObject (frame );
2747+ if (frameobj == NULL ) {
27542748 Py_DECREF (id );
2755- if (stat < 0 ) {
2756- goto fail ;
2757- }
2749+ goto fail ;
2750+ }
2751+ int stat = PyDict_SetItem (result , id , frameobj );
2752+ Py_DECREF (id );
2753+ if (stat < 0 ) {
2754+ goto fail ;
27582755 }
27592756 }
27602757 goto done ;
@@ -2764,7 +2761,7 @@ _PyThread_CurrentFrames(void)
27642761
27652762done :
27662763 HEAD_UNLOCK (runtime );
2767- _PyEval_StartTheWorldAll ( runtime );
2764+ _PyEval_StartTheWorld ( interp );
27682765 return result ;
27692766}
27702767
@@ -2790,35 +2787,32 @@ _PyThread_CurrentExceptions(void)
27902787 return NULL ;
27912788 }
27922789
2793- /* for i in all interpreters:
2794- * for t in all of i's thread states:
2795- * if t's frame isn't NULL, map t's id to its frame
2790+ /* for t in all of the current interpreter's thread states:
2791+ * if t's frame isn't NULL, map t's id to its exception
27962792 * Because these lists can mutate even when the GIL is held, we
27972793 * need to grab head_mutex for the duration.
27982794 */
2799- _PyEval_StopTheWorldAll (runtime );
2795+ PyInterpreterState * interp = tstate -> interp ;
2796+ _PyEval_StopTheWorld (interp );
28002797 HEAD_LOCK (runtime );
2801- PyInterpreterState * i ;
2802- for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
2803- _Py_FOR_EACH_TSTATE_UNLOCKED (i , t ) {
2804- _PyErr_StackItem * err_info = _PyErr_GetTopmostException (t );
2805- if (err_info == NULL ) {
2806- continue ;
2807- }
2808- PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2809- if (id == NULL ) {
2810- goto fail ;
2811- }
2812- PyObject * exc = err_info -> exc_value ;
2813- assert (exc == NULL ||
2814- exc == Py_None ||
2815- PyExceptionInstance_Check (exc ));
2816-
2817- int stat = PyDict_SetItem (result , id , exc == NULL ? Py_None : exc );
2818- Py_DECREF (id );
2819- if (stat < 0 ) {
2820- goto fail ;
2821- }
2798+ _Py_FOR_EACH_TSTATE_UNLOCKED (interp , t ) {
2799+ _PyErr_StackItem * err_info = _PyErr_GetTopmostException (t );
2800+ if (err_info == NULL ) {
2801+ continue ;
2802+ }
2803+ PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2804+ if (id == NULL ) {
2805+ goto fail ;
2806+ }
2807+ PyObject * exc = err_info -> exc_value ;
2808+ assert (exc == NULL ||
2809+ exc == Py_None ||
2810+ PyExceptionInstance_Check (exc ));
2811+
2812+ int stat = PyDict_SetItem (result , id , exc == NULL ? Py_None : exc );
2813+ Py_DECREF (id );
2814+ if (stat < 0 ) {
2815+ goto fail ;
28222816 }
28232817 }
28242818 goto done ;
@@ -2828,7 +2822,7 @@ _PyThread_CurrentExceptions(void)
28282822
28292823done :
28302824 HEAD_UNLOCK (runtime );
2831- _PyEval_StartTheWorldAll ( runtime );
2825+ _PyEval_StartTheWorld ( interp );
28322826 return result ;
28332827}
28342828
0 commit comments