state

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package state ports the skeleton of cpython/Python/pystate.c. v0.3 ships only the structs and the exception slot needed by the errors package; the lifecycle (Initialize/Finalize/NewInterpreter) lands in v0.7.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exception

type Exception interface {
	// IsException is a marker so unrelated types cannot satisfy this
	// interface by accident.
	IsException()
}

Exception is the interface state stores in the per-thread exception slot. The concrete type lives in the errors package; state knows only the marker method so the dependency graph is errors to state, not the reverse.

CPython: Include/cpython/pyerrors.h:L11 PyBaseExceptionObject

type Interpreter

type Interpreter struct {
	// contains filtered or unexported fields
}

Interpreter is the per-interpreter state. v0.7 fills in the dict of builtins, sys module, import locks, and so on.

CPython: Include/internal/pycore_interp.h:L113 PyInterpreterState

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime is the process-wide runtime state. Mirrors _PyRuntimeState.

CPython: Include/internal/pycore_runtime.h:L162 _PyRuntimeState

type Thread

type Thread struct {
	// contains filtered or unexported fields
}

Thread is the per-goroutine state. v0.3 carries the current exception pointer; v0.6 adds the frame stack and v0.7 adds the dict/globals slots.

CPython: Include/cpython/pystate.h:L75 PyThreadState

func NewThread

func NewThread() *Thread

NewThread builds a thread state owned by an implicit default interpreter. v0.3 has no real lifecycle; tests use this to obtain a Thread value to pass to errors.Set*.

CPython: Python/pystate.c:L915 PyThreadState_New

func (*Thread) CurrentException

func (t *Thread) CurrentException() Exception

CurrentException returns the current exception or nil. Mirrors _PyErr_Occurred.

CPython: Python/errors.c:L138 _PyErr_Occurred

func (*Thread) Interp

func (t *Thread) Interp() *Interpreter

Interp returns the interpreter that owns t. Mirrors PyThreadState_GetInterpreter.

CPython: Python/pystate.c:L2114 PyThreadState_GetInterpreter

func (*Thread) SetException

func (t *Thread) SetException(exc Exception)

SetException installs exc as the current exception. exc may be nil to clear.

CPython: Python/errors.c:L83 _PyErr_SetObject (excerpt)

func (*Thread) SwapException

func (t *Thread) SwapException(exc Exception) Exception

SwapException atomically replaces the current exception and returns the old value. Used by errors.Fetch.

CPython: Python/errors.c:L460 _PyErr_Fetch

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL