Expand description
Synchronization mechanisms which are aware of the existence of the Python interpreter.
The Python interpreter has multiple “stop the world” situations which may block threads, such as
- The Python global interpreter lock (GIL), on GIL-enabled builds of Python, or
- The Python garbage collector (GC), which pauses attached threads during collection.
To avoid deadlocks in these cases, threads should take care to be detached from the Python interpreter before performing operations which might block waiting for other threads attached to the Python interpreter.
This module provides synchronization primitives which are able to synchronize under these conditions.
Structs§
- GILOnce
Cell Deprecated - A write-once primitive similar to
std::sync::OnceLock<T>. - GILProtected
Deprecated - Value with concurrent access protected by the GIL.
- PyOnce
Lock - An equivalent to
std::sync::OnceLockfor initializing objects while attached to the Python interpreter.
Traits§
- Mutex
Ext - Extension trait for
std::sync::Mutexwhich helps avoid deadlocks between the Python interpreter and acquiring theMutex. - OnceExt
- Extension trait for
Onceto help avoid deadlocking when using aOncewhen attached to a Python thread. - Once
Lock Ext - Extension trait for
std::sync::OnceLockwhich helps avoid deadlocks between the Python interpreter and initialization with theOnceLock. - RwLock
Ext - Extension trait for
std::sync::RwLockwhich helps avoid deadlocks between the Python interpreter and acquiring theRwLock.
Functions§
- with_
critical_ section - Executes a closure with a Python critical section held on an object.
- with_
critical_ section2 - Executes a closure with a Python critical section held on two objects.