From: Sam Gross Date: Tue, 6 Jan 2026 14:40:14 +0000 (-0500) Subject: gh-143424: Fix assertion in _PyMutex_LockTimed (gh-143439) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=841b7482dd3584545d43fbfa78a27b1b5a3dfea3;p=thirdparty%2FPython%2Fcpython.git gh-143424: Fix assertion in _PyMutex_LockTimed (gh-143439) The assertion doesn't necessarily hold for `threading.Lock`, so allow the lock to be unlocked if `_PY_LOCK_PYTHONLOCK` is set on the flags. --- diff --git a/Python/lock.c b/Python/lock.c index 789065d81627..12b5ebc89aee 100644 --- a/Python/lock.c +++ b/Python/lock.c @@ -124,8 +124,11 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags) &entry, (flags & _PY_LOCK_DETACH) != 0); if (ret == Py_PARK_OK) { if (entry.handed_off) { - // We own the lock now. - assert(_Py_atomic_load_uint8_relaxed(&m->_bits) & _Py_LOCKED); + // We own the lock now. thread.Lock allows other threads + // to concurrently release the lock so we cannot assert that + // it is locked if _PY_LOCK_PYTHONLOCK is set. + assert(_Py_atomic_load_uint8_relaxed(&m->_bits) & _Py_LOCKED || + (flags & _PY_LOCK_PYTHONLOCK) != 0); return PY_LOCK_ACQUIRED; } }