From f82c951d1c5416f3550d544e50ff5662d3836e73 Mon Sep 17 00:00:00 2001 From: Jason Fried Date: Mon, 22 May 2017 16:58:55 -0700 Subject: [PATCH] bpo-30395 _PyGILState_Reinit deadlock fix (#1734) head_lock could be held by another thread when fork happened. We should reset it to avoid deadlock. --- Misc/ACKS | 1 + Python/pystate.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Misc/ACKS b/Misc/ACKS index 098c801fcb..b72c40c333 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -556,6 +556,7 @@ Eric Groo Daniel Andrade Groppe Dag Gruneau Filip Gruszczyński +Andrii Grynenko Grzegorz Grzywacz Thomas Guettler Yuyang Guo diff --git a/Python/pystate.c b/Python/pystate.c index 8e81707c7c..52899f124a 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -744,6 +744,10 @@ _PyGILState_Fini(void) void _PyGILState_Reinit(void) { +#ifdef WITH_THREAD + head_mutex = NULL; + HEAD_INIT(); +#endif PyThreadState *tstate = PyGILState_GetThisThreadState(); PyThread_delete_key(autoTLSkey); if ((autoTLSkey = PyThread_create_key()) == -1) -- 2.40.0