aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-03-21 10:01:16 -0400
committerGitHub <noreply@github.com>2024-03-21 10:01:16 -0400
commite728303532168efab7694c55c82ea19b18bf8385 (patch)
treee715ba949d2dff22a62c42b175b4e4676f68565e /Python/pylifecycle.c
parent1f8b24ef69896680d6ba6005e75e1cc79a744f9e (diff)
downloadcpython-e728303532168efab7694c55c82ea19b18bf8385.tar.gz
cpython-e728303532168efab7694c55c82ea19b18bf8385.zip
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.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 3a2c0a450ac..bc76822e72c 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -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);