@@ -2692,36 +2692,33 @@ _PyThread_CurrentFrames(void)
26922692 return NULL ;
26932693 }
26942694
2695- /* for i in all interpreters:
2696- * for t in all of i's thread states:
2697- * if t's frame isn't NULL, map t's id to its frame
2695+ /* for t in all of the current interpreter's thread states:
2696+ * if t's frame isn't NULL, map t's id to its frame
26982697 * Because these lists can mutate even when the GIL is held, we
26992698 * need to grab head_mutex for the duration.
27002699 */
2701- _PyEval_StopTheWorldAll (runtime );
2700+ PyInterpreterState * interp = tstate -> interp ;
2701+ _PyEval_StopTheWorld (interp );
27022702 HEAD_LOCK (runtime );
2703- PyInterpreterState * i ;
2704- for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
2705- _Py_FOR_EACH_TSTATE_UNLOCKED (i , t ) {
2706- _PyInterpreterFrame * frame = t -> current_frame ;
2707- frame = _PyFrame_GetFirstComplete (frame );
2708- if (frame == NULL ) {
2709- continue ;
2710- }
2711- PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2712- if (id == NULL ) {
2713- goto fail ;
2714- }
2715- PyObject * frameobj = (PyObject * )_PyFrame_GetFrameObject (frame );
2716- if (frameobj == NULL ) {
2717- Py_DECREF (id );
2718- goto fail ;
2719- }
2720- int stat = PyDict_SetItem (result , id , frameobj );
2703+ _Py_FOR_EACH_TSTATE_UNLOCKED (interp , t ) {
2704+ _PyInterpreterFrame * frame = t -> current_frame ;
2705+ frame = _PyFrame_GetFirstComplete (frame );
2706+ if (frame == NULL ) {
2707+ continue ;
2708+ }
2709+ PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2710+ if (id == NULL ) {
2711+ goto fail ;
2712+ }
2713+ PyObject * frameobj = (PyObject * )_PyFrame_GetFrameObject (frame );
2714+ if (frameobj == NULL ) {
27212715 Py_DECREF (id );
2722- if (stat < 0 ) {
2723- goto fail ;
2724- }
2716+ goto fail ;
2717+ }
2718+ int stat = PyDict_SetItem (result , id , frameobj );
2719+ Py_DECREF (id );
2720+ if (stat < 0 ) {
2721+ goto fail ;
27252722 }
27262723 }
27272724 goto done ;
@@ -2731,7 +2728,7 @@ _PyThread_CurrentFrames(void)
27312728
27322729done :
27332730 HEAD_UNLOCK (runtime );
2734- _PyEval_StartTheWorldAll ( runtime );
2731+ _PyEval_StartTheWorld ( interp );
27352732 return result ;
27362733}
27372734
@@ -2757,35 +2754,32 @@ _PyThread_CurrentExceptions(void)
27572754 return NULL ;
27582755 }
27592756
2760- /* for i in all interpreters:
2761- * for t in all of i's thread states:
2762- * if t's frame isn't NULL, map t's id to its frame
2757+ /* for t in all of the current interpreter's thread states:
2758+ * if t's frame isn't NULL, map t's id to its exception
27632759 * Because these lists can mutate even when the GIL is held, we
27642760 * need to grab head_mutex for the duration.
27652761 */
2766- _PyEval_StopTheWorldAll (runtime );
2762+ PyInterpreterState * interp = tstate -> interp ;
2763+ _PyEval_StopTheWorld (interp );
27672764 HEAD_LOCK (runtime );
2768- PyInterpreterState * i ;
2769- for (i = runtime -> interpreters .head ; i != NULL ; i = i -> next ) {
2770- _Py_FOR_EACH_TSTATE_UNLOCKED (i , t ) {
2771- _PyErr_StackItem * err_info = _PyErr_GetTopmostException (t );
2772- if (err_info == NULL ) {
2773- continue ;
2774- }
2775- PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2776- if (id == NULL ) {
2777- goto fail ;
2778- }
2779- PyObject * exc = err_info -> exc_value ;
2780- assert (exc == NULL ||
2781- exc == Py_None ||
2782- PyExceptionInstance_Check (exc ));
2783-
2784- int stat = PyDict_SetItem (result , id , exc == NULL ? Py_None : exc );
2785- Py_DECREF (id );
2786- if (stat < 0 ) {
2787- goto fail ;
2788- }
2765+ _Py_FOR_EACH_TSTATE_UNLOCKED (interp , t ) {
2766+ _PyErr_StackItem * err_info = _PyErr_GetTopmostException (t );
2767+ if (err_info == NULL ) {
2768+ continue ;
2769+ }
2770+ PyObject * id = PyLong_FromUnsignedLong (t -> thread_id );
2771+ if (id == NULL ) {
2772+ goto fail ;
2773+ }
2774+ PyObject * exc = err_info -> exc_value ;
2775+ assert (exc == NULL ||
2776+ exc == Py_None ||
2777+ PyExceptionInstance_Check (exc ));
2778+
2779+ int stat = PyDict_SetItem (result , id , exc == NULL ? Py_None : exc );
2780+ Py_DECREF (id );
2781+ if (stat < 0 ) {
2782+ goto fail ;
27892783 }
27902784 }
27912785 goto done ;
@@ -2795,7 +2789,7 @@ _PyThread_CurrentExceptions(void)
27952789
27962790done :
27972791 HEAD_UNLOCK (runtime );
2798- _PyEval_StartTheWorldAll ( runtime );
2792+ _PyEval_StartTheWorld ( interp );
27992793 return result ;
28002794}
28012795
0 commit comments