Trait MutexExt

Source
pub trait MutexExt<'a, T, R>: Sealed
where Self: 'a,
{ // Required method fn lock_py_attached(&'a self, py: Python<'_>) -> R; }
Expand description

Extension trait for std::sync::Mutex which helps avoid deadlocks between the Python interpreter and acquiring the Mutex.

Required Methods§

Source

fn lock_py_attached(&'a self, py: Python<'_>) -> R

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.

Implementations on Foreign Types§

Source§

impl<'a, R, T> MutexExt<'a, T, ArcMutexGuard<R, T>> for Arc<Mutex<R, T>>
where R: RawMutex, Self: 'a,

Available on crate feature arc_lock only.
Source§

fn lock_py_attached(&self, _py: Python<'_>) -> ArcMutexGuard<R, T>

Source§

impl<'a, R: RawMutex, T> MutexExt<'a, T, MutexGuard<'a, R, T>> for Mutex<R, T>

Available on crate feature lock_api only.
Source§

fn lock_py_attached(&'a self, _py: Python<'_>) -> MutexGuard<'a, R, T>

Source§

impl<'a, T> MutexExt<'a, T, Result<MutexGuard<'a, T>, PoisonError<MutexGuard<'a, T>>>> for Mutex<T>

Source§

fn lock_py_attached(&'a self, _py: Python<'_>) -> LockResult<MutexGuard<'a, T>>

Implementors§

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here