pyctx

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunningLoop

func RunningLoop(ctx context.Context) bool

Whether the context was marked as running an event loop

func SnapshotMainForTests

func SnapshotMainForTests() (restore func())

Returns the restore of the main thread context to the values it holds now

func With

func With(ctx context.Context, c *Context) context.Context

Runs work under c the way Context.run enters it

func WithRunningLoop

func WithRunningLoop(ctx context.Context) context.Context

Marks a context as served by a goroutine running an event loop, asyncio.get_running_loop succeeding

func WithoutRunningLoop

func WithoutRunningLoop(ctx context.Context) context.Context

Copy of the context as a fresh worker thread sees it, no event loop running there

Types

type Context

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

Mutable mapping of variables to values that one logical thread of execution runs inside

func CopyContext

func CopyContext(ctx context.Context) *Context

Copy of the current context like contextvars.copy_context

func Current

func Current(ctx context.Context) *Context

Context the caller runs inside, the main thread context when none was entered

func New

func New() *Context

Empty context like contextvars.Context()

func (*Context) Copy

func (c *Context) Copy() *Context

Independent shallow copy holding the same values

func (*Context) Items

func (c *Context) Items() []Item

Every set variable with its value in first set order

type Item

type Item struct {
	Var   *Var
	Value any
}

Variable value pair of a context

type Token

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

Restores a variable to what it held before one Set

type Var

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

Variable whose value lives in a Context, read back as its default where the Context never set it

func NewVar

func NewVar(name string, def any) *Var

Declares a variable with its default value

func (*Var) Get

func (v *Var) Get(ctx context.Context) any

Value in the current context, else the default

func (*Var) Name

func (v *Var) Name() string

Name the variable was declared with

func (*Var) Reset

func (v *Var) Reset(ctx context.Context, t *Token) error

Undoes the Set that produced the token, refusing a reused, foreign variable or foreign context token

func (*Var) Set

func (v *Var) Set(ctx context.Context, value any) *Token

Sets the value in the current context and returns the token that undoes it

Jump to

Keyboard shortcuts

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