Skip to content

Commit c9e7b08

Browse files
committed
Fix failing builds.
1 parent 13e96de commit c9e7b08

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Include/internal/pycore_interp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ _PyInterpreterState_PreventMain(PyInterpreterState *interp);
421421
PyAPI_FUNC(int)
422422
_PyInterpreterState_IsRunningAllowed(PyInterpreterState *interp);
423423

424+
PyAPI_FUNC(PyThreadState *)
425+
_PyInterpreterState_ThreadHeadSafe(PyInterpreterState *interp);
426+
424427
#define RARE_EVENT_INTERP_INC(interp, name) \
425428
do { \
426429
/* saturating add */ \

Modules/_interpretersmodule.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,18 +711,17 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
711711
return NULL;
712712
}
713713

714-
HEAD_LOCK(&_PyRuntime);
715-
if (interp->threads.head != NULL)
714+
// It would be nice if we could just lock the runtime here, but
715+
// unfortunately we don't have access to private PyMutex functions from this module.
716+
if (_PyInterpreterState_ThreadHeadSafe(interp) != NULL)
716717
{
717718
/*
718719
* We're in a weird limbo where the main thread isn't set but
719720
* the thread states haven't fully cleared yet.
720721
*/
721-
HEAD_UNLOCK(&_PyRuntime);
722722
PyErr_SetString(PyExc_InterpreterError, "interpreter is still finishing");
723723
return NULL;
724724
}
725-
HEAD_UNLOCK(&_PyRuntime);
726725

727726
/*
728727
* Running main has now been prevented, the interpreter will

Python/pystate.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,6 +2557,16 @@ PyThreadState_Next(PyThreadState *tstate) {
25572557
}
25582558

25592559

2560+
PyThreadState *
2561+
_PyInterpreterState_ThreadHeadSafe(PyInterpreterState *interp)
2562+
{
2563+
HEAD_LOCK(&_PyRuntime);
2564+
PyThreadState *tstate = interp->threads.head;
2565+
HEAD_UNLOCK(&_PyRuntime);
2566+
return tstate;
2567+
}
2568+
2569+
25602570
/********************************************/
25612571
/* reporting execution state of all threads */
25622572
/********************************************/

0 commit comments

Comments
 (0)