python

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 10 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

This section is empty.

Types

type Callback added in v1.4.0

type Callback struct {
	Name       string
	Definition *py.PyMethodDef
	Object     py.PyObjectPtr
}

func NewCallback added in v1.4.0

func NewCallback(name string, f callbackFunc) (*Callback, error)

type ContextAwareMutex

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

A ContextAwareMutex implements a mutex lock that allows for an optional context to be provided so a caller can control if they want a deadline or timeout.

func NewContextAwareMutex

func NewContextAwareMutex() *ContextAwareMutex

func (*ContextAwareMutex) AssertLocked

func (c *ContextAwareMutex) AssertLocked()

AssertLocked panics if the ContextAwareMutex is not currently locked by someone.

func (*ContextAwareMutex) Lock

func (c *ContextAwareMutex) Lock() error

Lock the mutex using a background context.

func (*ContextAwareMutex) LockWithContext

func (c *ContextAwareMutex) LockWithContext(ctx context.Context) error

LockWithContext will attempt to take the lock but uses the provided context.Context to allow cancellation.

func (*ContextAwareMutex) Unlock

func (c *ContextAwareMutex) Unlock()

Unlock the mutex. Panics if the mutex is not currently locked in order to speed up debugging.

type InterpreterTicket

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

An InterpreterTicket represents ownership of the interpreter of a particular Runtime. Other than its id, it's opaque to the user.

func (*InterpreterTicket) Id

func (i *InterpreterTicket) Id() int64

Id provides a unique (to the backing Runtime) identifier for an interpreter. The caller may use this for identifying if they're re-using an interpreter.

type Mode added in v1.4.0

type Mode string
const (
	MultiMode   Mode = "multi"
	SingleMode  Mode = "single"
	LegacyMode  Mode = "legacy"
	InvalidMode Mode = "invalid"
)

func StringAsMode added in v1.4.0

func StringAsMode(s string) Mode

type MultiInterpreterRuntime

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

MultiInterpreterRuntime creates and manages multiple Python sub-interpreters.

func NewMultiInterpreterRuntime

func NewMultiInterpreterRuntime(exe string, cnt int, legacyMode bool, logger *service.Logger) (*MultiInterpreterRuntime, error)

func (*MultiInterpreterRuntime) Acquire

func (*MultiInterpreterRuntime) Apply

func (r *MultiInterpreterRuntime) Apply(token *InterpreterTicket, _ context.Context, f func() error) error

func (*MultiInterpreterRuntime) Map

Map a function fn over all the interpreters, one at a time. Useful for initializing all interpreters to a given state.

func (*MultiInterpreterRuntime) Release

func (r *MultiInterpreterRuntime) Release(token *InterpreterTicket) error

func (*MultiInterpreterRuntime) Start

Start the Python runtime. A MultiInterpreterRuntime centralizes modification of the main interpreter in a go routine.

func (*MultiInterpreterRuntime) Stop

Stop a running Python Runtime.

type Runtime

type Runtime interface {
	// Start the Python runtime.
	Start(ctx context.Context) error

	// Stop the Python runtime, removing all interpreter state.
	Stop(ctx context.Context) error

	// Acquire ownership of an interpreter until Release is called, providing
	// a ticket on success or returning err on error.
	Acquire(ctx context.Context) (ticket *InterpreterTicket, err error)

	// Release ownership of an interpreter identified by the given
	// InterpreterTicket.
	Release(token *InterpreterTicket) error

	// Apply a function f over the interpreter described by the given
	// InterpreterTicket.
	Apply(token *InterpreterTicket, ctx context.Context, f func() error) error

	// Map a function f over all possible interpreters.
	// In the case of multiple interpreters, an error aborts mapping over the
	// remainder.
	Map(ctx context.Context, f func(ticket *InterpreterTicket) error) error
}

A Runtime for a Python interpreter.

type Serializer added in v1.4.0

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

func NewSerializer added in v1.4.0

func NewSerializer() (*Serializer, error)

NewSerializer attempts to compile, import, and prepare a set of Python objects to assist serialization.

The caller must manage the interpreter state for this to succeed.

func (*Serializer) DecRef added in v1.4.0

func (s *Serializer) DecRef()

func (*Serializer) JsonBytes added in v1.4.0

func (s *Serializer) JsonBytes(obj py.PyObjectPtr) ([]byte, error)

JsonBytes serializes the given Python object to JSON, encoded to utf-8 bytes.

func (*Serializer) JsonString added in v1.4.0

func (s *Serializer) JsonString(obj py.PyObjectPtr) (string, error)

JsonString serializes the given Python object to JSON.

func (*Serializer) Pickle added in v1.4.0

func (s *Serializer) Pickle(obj py.PyObjectPtr) ([]byte, error)

Pickle the given Python object.

type SingleInterpreterRuntime

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

SingleInterpreterRuntime provides an implementation for using main Python interpreter.

func NewSingleInterpreterRuntime

func NewSingleInterpreterRuntime(exe string, logger *service.Logger) (*SingleInterpreterRuntime, error)

func (*SingleInterpreterRuntime) Acquire

func (*SingleInterpreterRuntime) Apply

func (r *SingleInterpreterRuntime) Apply(ticket *InterpreterTicket, _ context.Context, f func() error) error

func (*SingleInterpreterRuntime) Map

func (*SingleInterpreterRuntime) Release

func (r *SingleInterpreterRuntime) Release(ticket *InterpreterTicket) error

func (*SingleInterpreterRuntime) Start

func (*SingleInterpreterRuntime) Stop

Jump to

Keyboard shortcuts

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