pythonEngine

package
v0.36.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultPythonPath = "python3"

DefaultPythonPath is the default python3 executable path

Variables

This section is empty.

Functions

func ResolvePythonPath

func ResolvePythonPath(pythonPath string) (string, error)

ResolvePythonPath resolves the python executable path. If pythonPath is empty, it tries "python3" first, then "python".

func ValidatePython

func ValidatePython(pythonPath string) error

ValidatePython checks if the python executable is available.

Types

type ProcessPool

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

ProcessPool manages python3 subprocess invocations with concurrency control and timeout. It pre-starts Python processes that block at sys.stdin.read(), eliminating startup overhead from the request path. Each request consumes one worker (process exits after handling one request), and a replacement is started in the background.

func NewFileProcessPool

func NewFileProcessPool(config types.Config, functionName string, path string, pythonPath string, timeout time.Duration, maxRunning int, configuration types.Configuration) *ProcessPool

NewFileProcessPool creates a pool for .py file paths. The functionName is baked into the script at construction time. idleTimeout controls how long an idle worker sits in the pool before being killed (0 = no limit).

func NewStringProcessPool

func NewStringProcessPool(config types.Config, functionName string, script string, pythonPath string, timeout time.Duration, maxRunning int, configuration types.Configuration) *ProcessPool

NewStringProcessPool creates a pool for inline script strings. The functionName is baked into the script at construction time. idleTimeout controls how long an idle worker sits in the pool before being killed (0 = no limit).

func (*ProcessPool) Execute

func (p *ProcessPool) Execute(msg string, metadata map[string]string, msgType string, dataType string) (map[string]interface{}, error)

Execute runs the python script in a pre-warmed subprocess, passing input as JSON via stdin and reading the result from stdout. stderr is captured and returned as error.

func (*ProcessPool) SetIdleTimeout

func (p *ProcessPool) SetIdleTimeout(d time.Duration)

SetIdleTimeout sets the idle timeout for the pool. Workers that sit idle in the ready channel longer than this duration are killed and their slot is released. Set to 0 to disable idle eviction. Must be called before any Execute() calls.

func (*ProcessPool) Shutdown

func (p *ProcessPool) Shutdown()

Shutdown stops the warmLoop, kills all idle workers, and waits for in-flight executions to complete.

Jump to

Keyboard shortcuts

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