Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a002c0

Browse files
committed
Fix the GIL with subinterpreters. Hopefully this will allow mod_wsgi to work with 3.2.
(we need some tests for this)
1 parent ad30c42 commit 6a002c0

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Python/ceval_gil.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,15 @@ static void recreate_gil(void)
334334

335335
static void drop_gil(PyThreadState *tstate)
336336
{
337-
/* NOTE: tstate is allowed to be NULL. */
338337
if (!_Py_atomic_load_relaxed(&gil_locked))
339338
Py_FatalError("drop_gil: GIL is not locked");
340-
if (tstate != NULL &&
341-
tstate != _Py_atomic_load_relaxed(&gil_last_holder))
342-
Py_FatalError("drop_gil: wrong thread state");
339+
/* tstate is allowed to be NULL (early interpreter init) */
340+
if (tstate != NULL) {
341+
/* Sub-interpreter support: threads might have been switched
342+
under our feet using PyThreadState_Swap(). Fix the GIL last
343+
holder variable so that our heuristics work. */
344+
_Py_atomic_store_relaxed(&gil_last_holder, tstate);
345+
}
343346

344347
MUTEX_LOCK(gil_mutex);
345348
_Py_ANNOTATE_RWLOCK_RELEASED(&gil_locked, /*is_write=*/1);

0 commit comments

Comments
 (0)