pyo3::sync

Trait OnceLockExt

Source
pub trait OnceLockExt<T>: Sealed {
    // Required method
    fn get_or_init_py_attached<F>(&self, py: Python<'_>, f: F) -> &T
       where F: FnOnce() -> T;
}
Available on rustc_has_once_lock only.
Expand description

interpreter and initialization with the OnceLock.

Required Methods§

Source

fn get_or_init_py_attached<F>(&self, py: Python<'_>, f: F) -> &T
where 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.

Implementations on Foreign Types§

Source§

impl<T> OnceLockExt<T> for OnceLock<T>

Source§

fn get_or_init_py_attached<F>(&self, py: Python<'_>, f: F) -> &T
where F: FnOnce() -> T,

Implementors§

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