pub trait OnceLockExt<T>: Sealed {
// Required method
fn get_or_init_py_attached<F>(&self, py: Python<'_>, f: F) -> &T
where F: FnOnce() -> T;
}
Expand description
interpreter and initialization with the OnceLock
.
Required Methods§
Sourcefn get_or_init_py_attached<F>(&self, py: Python<'_>, f: F) -> &Twhere
F: FnOnce() -> T,
fn get_or_init_py_attached<F>(&self, py: Python<'_>, f: F) -> &Twhere
F: FnOnce() -> T,
Initializes this OnceLock
with the given closure if it has not been initialized yet.
If this function would block, this function detaches from the Python interpreter and
reattaches before calling f
. This avoids deadlocks between the Python interpreter and
the OnceLock
in cases where f
can call arbitrary Python code, as calling arbitrary
Python code can lead to f
itself blocking on the Python interpreter.
By detaching from the Python interpreter before blocking, this ensures that if f
blocks
then the Python interpreter cannot be blocked by f
itself.
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.