gh-116522: Stop the world before fork() and during shutdown (#116607)
This changes the free-threaded build to perform a stop-the-world pause before deleting other thread states when forking and during shutdown. This fixes some crashes when using multiprocessing and during shutdown when running with `PYTHON_GIL=0`. This also changes `PyOS_BeforeFork` to acquire the runtime lock (i.e., `HEAD_LOCK(&_PyRuntime)`) before forking to ensure that data protected by the runtime lock (and not just the GIL or stop-the-world) is in a consistent state before forking.
This commit is contained in:
@@ -1911,6 +1911,9 @@ Py_FinalizeEx(void)
|
||||
int malloc_stats = tstate->interp->config.malloc_stats;
|
||||
#endif
|
||||
|
||||
/* Ensure that remaining threads are detached */
|
||||
_PyEval_StopTheWorldAll(runtime);
|
||||
|
||||
/* Remaining daemon threads will automatically exit
|
||||
when they attempt to take the GIL (ex: PyEval_RestoreThread()). */
|
||||
_PyInterpreterState_SetFinalizing(tstate->interp, tstate);
|
||||
|
||||
Reference in New Issue
Block a user