MutexExt

Trait MutexExt 

Source
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§

Source

type LockResult<'a> where Self: 'a

The result type returned by the lock_py_attached method.

Required Methods§

Source

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.

Implementations on Foreign Types§

Source§

impl<T> MutexExt<T> for Mutex<T>

Source§

type LockResult<'a> = Result<MutexGuard<'a, T>, PoisonError<MutexGuard<'a, T>>> where Self: 'a

Source§

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

Implementors§