File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -334,12 +334,15 @@ static void recreate_gil(void)
334334
335335static 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 );
You can’t perform that action at this time.
0 commit comments