pub trait MutexExt<T>: Sealed {
// Required method
fn lock_py_attached(&self, py: Python<'_>) -> LockResult<MutexGuard<'_, T>>;
}
Expand description
Extension trait for std::sync::Mutex
which helps avoid deadlocks between
the Python interpreter and acquiring the Mutex
.
Required Methods§
Sourcefn lock_py_attached(&self, py: Python<'_>) -> LockResult<MutexGuard<'_, T>>
fn lock_py_attached(&self, py: Python<'_>) -> LockResult<MutexGuard<'_, T>>
Lock this Mutex
in a manner that cannot deadlock with the Python interpreter.
Before attempting to lock the mutex, this function detaches from the
Python runtime. When the lock is acquired, it re-attaches to the Python
runtime before returning the LockResult
. This avoids deadlocks between
the GIL and other global synchronization events triggered by the Python
interpreter.