Skip to main content

PyGlobalState

Struct PyGlobalState 

Source
pub struct PyGlobalState {
Show 33 fields pub interpreter_id: i64, pub runtime_root_id: i64, pub whence: InterpreterWhence, pub is_main: bool, pub config: PyConfig, pub module_defs: BTreeMap<&'static str, &'static PyModuleDef>, pub frozen: HashMap<&'static str, FrozenModule, RandomState>, pub stacksize: AtomicCell<usize>, pub thread_count: AtomicCell<usize>, pub atexit_funcs: PyMutex<Vec<PyRc<(PyObjectRef, FuncArgs)>>>, pub codec_registry: CodecsRegistry, pub struct_format_cache: FormatSpecCache, pub finalizing: AtomicBool, pub warnings: WarningsState, pub override_frozen_modules: AtomicCell<isize>, pub before_forkers: PyMutex<Vec<PyObjectRef>>, pub after_forkers_child: PyMutex<Vec<PyObjectRef>>, pub after_forkers_parent: PyMutex<Vec<PyObjectRef>>, pub int_max_str_digits: AtomicCell<usize>, pub switch_interval: AtomicCell<f64>, pub global_trace_func: PyMutex<Option<PyObjectRef>>, pub global_profile_func: PyMutex<Option<PyObjectRef>>, pub type_mutex: PyMutex<()>, pub monitoring: PyMutex<MonitoringState>, pub monitoring_events: AtomicCell<u32>, pub instrumentation_version: AtomicU64, pub gc: GcInterpreterState, pub feature_flags: InterpFeatureFlags, pub own_gil: bool, pub running_main: AtomicBool, pub ready: AtomicBool, pub id_refcount: AtomicI64, pub require_idref: AtomicBool, /* private fields */
}
Expand description

Per-interpreter shared state (≈ CPython PyInterpreterState).

Not process-global: each Interpreter (main or subinterpreter) owns its own PyGlobalState. Process-wide pieces live elsewhere (Context::genesis, GC, the interpreter registry in runtime).

Fields§

§interpreter_id: i64

Unique process-global interpreter id (main is MAIN_INTERPRETER_ID).

§runtime_root_id: i64

Top-level interpreter whose runtime owns this interpreter.

§whence: InterpreterWhence

How this interpreter was created.

§is_main: bool

True for every top-level (non-sub) interpreter, each of which keeps its own signal and main-thread bookkeeping. Only the first one registered becomes the process main — see runtime::main_interpreter_id.

§config: PyConfig§module_defs: BTreeMap<&'static str, &'static PyModuleDef>§frozen: HashMap<&'static str, FrozenModule, RandomState>§stacksize: AtomicCell<usize>§thread_count: AtomicCell<usize>§atexit_funcs: PyMutex<Vec<PyRc<(PyObjectRef, FuncArgs)>>>

Registered atexit callbacks, newest first. Shared ownership so atexit.unregister can keep the entry it is comparing alive while the list is unlocked, and still recognize it afterwards by identity.

§codec_registry: CodecsRegistry§struct_format_cache: FormatSpecCache§finalizing: AtomicBool§warnings: WarningsState§override_frozen_modules: AtomicCell<isize>§before_forkers: PyMutex<Vec<PyObjectRef>>§after_forkers_child: PyMutex<Vec<PyObjectRef>>§after_forkers_parent: PyMutex<Vec<PyObjectRef>>§int_max_str_digits: AtomicCell<usize>§switch_interval: AtomicCell<f64>§global_trace_func: PyMutex<Option<PyObjectRef>>

Global trace function for all threads (set by sys._settraceallthreads)

§global_profile_func: PyMutex<Option<PyObjectRef>>

Global profile function for all threads (set by sys._setprofileallthreads)

§type_mutex: PyMutex<()>

Global type mutation/versioning mutex for CPython-style FT type operations.

§monitoring: PyMutex<MonitoringState>

sys.monitoring state (tool names, events, callbacks)

§monitoring_events: AtomicCell<u32>

Fast-path mask: OR of all tools’ events. 0 means no monitoring overhead.

§instrumentation_version: AtomicU64

Incremented on every monitoring state change. Code objects compare their local version against this to decide whether re-instrumentation is needed.

§gc: GcInterpreterState

This interpreter’s garbage collector policy and results.

§feature_flags: InterpFeatureFlags

Isolated-interpreter feature flags (PEP 684 / PEP 734 config).

§own_gil: bool

Whether the interpreter was configured with gil="own".

§running_main: AtomicBool

Whether __main__ is currently executing via _interpreters.exec / run_*.

§ready: AtomicBool

True after initialize() has finished (CPython “ready”).

§id_refcount: AtomicI64

Optional ID refcount used by _interpreters.create(reqrefs=True).

§require_idref: AtomicBool

When true, dropping the last ID ref destroys the interpreter.

Implementations§

Source§

impl PyGlobalState

Source

pub fn is_main_interpreter(&self) -> bool

Source

pub fn allow_fork(&self) -> bool

Source

pub fn allow_exec(&self) -> bool

Source

pub fn allow_threads(&self) -> bool

Source

pub fn allow_daemon_threads(&self) -> bool

Source

pub fn config(&self) -> InterpreterConfig

The config this interpreter was created with, rebuilt from the flags it kept (_PyInterpreterConfig_InitFromState).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Helper for T

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> PrimitiveIntRandomBounds for T

Source§

impl<T> PrimitiveSignedRandomBounds for T

Source§

impl<T> PyThreadingConstraint for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U