Skip to content

Commit 6d2c945

Browse files
Replace use PyGILState_Ensure with PyThreadState_New + _PyThreadState_Attach
1 parent 4491118 commit 6d2c945

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

Modules/faulthandler.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -715,19 +715,21 @@ faulthandler_thread(void *unused)
715715

716716
if (!interp_is_freed(interp)) {
717717

718-
#ifdef Py_GIL_DISABLED
719-
_PyEval_StopTheWorld(interp);
720-
#else
721-
PyGILState_STATE gil_state = PyGILState_Ensure();
722-
#endif
723-
errmsg = _Py_DumpTracebackThreads(thread.fd, interp, NULL, 1);
724-
ok = (errmsg == NULL);
718+
PyThreadState* ts = PyThreadState_New(interp);
719+
if (ts) {
720+
_PyThreadState_Attach(ts);
721+
_PyEval_StopTheWorld(interp);
725722

726-
#ifdef Py_GIL_DISABLED
727-
_PyEval_StartTheWorld(interp);
728-
#else
729-
PyGILState_Release(gil_state);
730-
#endif
723+
errmsg = _Py_DumpTracebackThreads(thread.fd, interp, NULL);
724+
ok = (errmsg == NULL);
725+
726+
_PyEval_StartTheWorld(interp);
727+
PyThreadState_Clear(ts);
728+
PyThreadState_DeleteCurrent();
729+
}
730+
else {
731+
fprintf(stderr, "faulthandler_thread: PyThreadState_New failed\n");
732+
}
731733
}
732734

733735

0 commit comments

Comments
 (0)