Documentation
¶
Index ¶
- Constants
- func DropGlobalReferences(objs []py.PyObjectPtr, ctx context.Context) error
- func Evaluate(fn func() error, c chan error, ctx context.Context) error
- func Spawn(legacyMode bool, ctx context.Context) (*subInterpreter, error)
- func StopSub(subInterpreter *subInterpreter, ctx context.Context) error
- type Callback
- type ContextAwareMutex
- type InterpreterTicket
- type Mode
- type MultiInterpreterRuntime
- func (r *MultiInterpreterRuntime) Acquire(ctx context.Context) (*InterpreterTicket, error)
- func (r *MultiInterpreterRuntime) Apply(ticket *InterpreterTicket, _ context.Context, f func() error) error
- func (r *MultiInterpreterRuntime) Map(ctx context.Context, f func(t *InterpreterTicket) error) error
- func (r *MultiInterpreterRuntime) Release(ticket *InterpreterTicket) error
- func (r *MultiInterpreterRuntime) Start(ctx context.Context) error
- func (r *MultiInterpreterRuntime) Stop(ctx context.Context) error
- type Runtime
- type Serializer
- type SerializerMode
- type SingleInterpreterRuntime
- func (r *SingleInterpreterRuntime) Acquire(ctx context.Context) (*InterpreterTicket, error)
- func (r *SingleInterpreterRuntime) Apply(ticket *InterpreterTicket, ctx context.Context, f func() error) error
- func (r *SingleInterpreterRuntime) Map(ctx context.Context, f func(ticket *InterpreterTicket) error) error
- func (r *SingleInterpreterRuntime) Release(ticket *InterpreterTicket) error
- func (r *SingleInterpreterRuntime) Start(ctx context.Context) error
- func (r *SingleInterpreterRuntime) Stop(ctx context.Context) error
Constants ¶
const SerializerMetaKey = "_python_serializer"
Variables ¶
This section is empty.
Functions ¶
func DropGlobalReferences ¶ added in v1.5.0
func DropGlobalReferences(objs []py.PyObjectPtr, ctx context.Context) error
DropGlobalReferences to a list of PyObjectPtr.
func Evaluate ¶ added in v1.7.0
Evaluate a given function fn in the context of the main interpreter. A response is provided via the channel c.
XXX This may look a little odd, both returning an error and using a channel, but it's to avoid having to allocate a channel for each call as this function will be called frequently.
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
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 MultiInterpreterRuntime ¶
type MultiInterpreterRuntime struct {
// contains filtered or unexported fields
}
MultiInterpreterRuntime creates and manages multiple Python sub-interpreters.
func (*MultiInterpreterRuntime) Acquire ¶
func (r *MultiInterpreterRuntime) Acquire(ctx context.Context) (*InterpreterTicket, error)
func (*MultiInterpreterRuntime) Apply ¶
func (r *MultiInterpreterRuntime) Apply(ticket *InterpreterTicket, _ context.Context, f func() error) error
func (*MultiInterpreterRuntime) Map ¶
func (r *MultiInterpreterRuntime) Map(ctx context.Context, f func(t *InterpreterTicket) error) error
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(ticket *InterpreterTicket) error
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 SerializerMode ¶ added in v1.5.0
type SerializerMode string
const ( // Pickle SerializerMode will pickle any Python results. Pickle SerializerMode = "pickle" // Bloblang SerializerMode will approximate JSON serialization used by Bloblang. Bloblang SerializerMode = "bloblang" // None SerializerMode will not attempt serialization and simply pass Python object pointers. None SerializerMode = "none" InvalidSerializer SerializerMode = "invalid" )
func StringAsSerializerMode ¶ added in v1.5.0
func StringAsSerializerMode(s string) SerializerMode
type SingleInterpreterRuntime ¶
type SingleInterpreterRuntime struct {
// contains filtered or unexported fields
}
SingleInterpreterRuntime provides an implementation for using main Python interpreter.
func (*SingleInterpreterRuntime) Acquire ¶
func (r *SingleInterpreterRuntime) Acquire(ctx context.Context) (*InterpreterTicket, error)
func (*SingleInterpreterRuntime) Apply ¶
func (r *SingleInterpreterRuntime) Apply(ticket *InterpreterTicket, ctx context.Context, f func() error) error
func (*SingleInterpreterRuntime) Map ¶
func (r *SingleInterpreterRuntime) Map(ctx context.Context, f func(ticket *InterpreterTicket) error) error
func (*SingleInterpreterRuntime) Release ¶
func (r *SingleInterpreterRuntime) Release(ticket *InterpreterTicket) error