lifecycle

package
v0.12.3 Latest Latest
Warning

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

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

Documentation

Overview

Package lifecycle ports the cpython/Python/pylifecycle.c boot sequence: pre-init, core init, main init, finalize. v0.7 lands the core skeleton; later subtasks (1622-F path config, 1622-G finalize, 1622-H Main) flesh out each phase as the depended-on subsystems land.

Index

Constants

This section is empty.

Variables

View Source
var ErrModuleNotImplemented = errors.New("lifecycle: -m module dispatch lands with v0.8 (spec 1623)")

ErrModuleNotImplemented is returned by Main when the resolved config asks for `-m module`. The import-driven module entry lands with v0.8 (spec 1623); v0.7 only handles -c, scripts, and the REPL.

Functions

func Finalize

func Finalize(rt *state.Runtime) initconfig.Status

Finalize tears the runtime down. Mirrors the staged shutdown order of _Py_Finalize: flip the finalizing flags first so other goroutines stop taking the GIL, then walk the per-phase teardown hooks in the order CPython documents.

The v0.7 skeleton lands the phase scaffolding. Each per-phase helper is a no-op until the owning subtask attaches:

  • flush sys.stdio: 1651-sys-D
  • signal handlers: 1639 (already in place; finalize hook lands with the lifecycle wiring task)
  • import / modules teardown: v0.8 spec 1623
  • faulthandler / hash stats: deferred to their own subtasks

Returns Status so the caller can distinguish a clean shutdown from a flush failure (CPython returns -1 in that case).

CPython: Python/pylifecycle.c:2016 _Py_Finalize

func Initialize

func Initialize(rt *state.Runtime, config *initconfig.PyConfig) (*state.Thread, initconfig.Status)

Initialize is the public Py_InitializeFromConfig entry. It runs the pre-init then core init then main init phases against rt and returns the bound thread state.

rt may be nil; a fresh runtime is allocated in that case so callers in tests and cmd/gopy do not have to thread one through by hand.

CPython: Python/pylifecycle.c:1422 Py_InitializeFromConfig

func Main

func Main(argv []string, stdin io.Reader, stdout, stderr io.Writer) int

Main is the gopy equivalent of CPython's Py_Main. It parses argv into a PyConfig, runs the init / dispatch / finalize sequence, and returns the process exit code.

argv follows the Py_Main contract: argv[0] is the program name and the option scan starts at argv[1]. MainOSArgs passes os.Args directly so the binary name is always present.

The dispatch arms map to the pythonrun ports landed in spec 1624:

  • RunCommand (-c) -> pythonrun.RunSimpleString
  • RunFilename -> pythonrun.RunAnyFile
  • RunModule (-m) -> ErrModuleNotImplemented (v0.8 / spec 1623)
  • default -> pythonrun.InteractiveLoop

stdin/stdout/stderr are threaded as parameters so tests can capture output; the cmd/gopy binary passes os.Stdin/Stdout/Stderr.

CPython: Modules/main.c:811 Py_Main

func MainOSArgs

func MainOSArgs() int

MainOSArgs is the convenience entry that wires Main to the real process argv and standard streams.

Types

This section is empty.

Jump to

Keyboard shortcuts

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