pub trait MutexExt<T>: Sealed {
type LockResult<'a>
where Self: 'a;
// Required method
fn lock_py_attached(&self, py: Python<'_>) -> Self::LockResult<'_>;
}
Expand description
Extension trait for std::sync::Mutex
which helps avoid deadlocks between
the Python interpreter and acquiring the Mutex
.
Required Associated Types§
Sourcetype LockResult<'a>
where
Self: 'a
type LockResult<'a> where Self: 'a
The result type returned by the lock_py_attached
method.
Required Methods§
Sourcefn lock_py_attached(&self, py: Python<'_>) -> Self::LockResult<'_>
fn lock_py_attached(&self, py: Python<'_>) -> Self::LockResult<'_>
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.