Documentation
¶
Overview ¶
Package runner 提供 Python 子进程运行器。 管理 Python 进程的启动、stdin/stdout JSON lines 通信和生命周期。
Index ¶
- func ConvertEnv(raw map[string]interface{}) map[string]string
- func DefaultStderrHandler(prefix string) func(string)
- type Config
- type Runner
- func (r *Runner) Close() error
- func (r *Runner) CloseStdin() error
- func (r *Runner) ReadLine(ctx context.Context) ([]byte, error)
- func (r *Runner) SetStderrCallback(fn func(line string))
- func (r *Runner) Start(ctx context.Context) error
- func (r *Runner) WriteLine(ctx context.Context, line []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertEnv ¶
ConvertEnv 将 map[string]interface{} 转为 map[string]string。 用于兼容 YAML 中非字符串类型的环境变量值(如 WORKER_COUNT: 8)。
func DefaultStderrHandler ¶
DefaultStderrHandler 返回一个默认的 stderr 日志处理器。 自动解析 Python logging 的级别前缀(如 INFO:、WARNING:、ERROR:), 并使用对应的 Go 日志级别输出。未识别的前缀默认为 WARN。 prefix 为日志来源标识,如 "[python-processor]"。
Types ¶
type Config ¶
type Config struct {
// Script Python 脚本路径(必填)
Script string `json:"script"`
// PythonExec Python 可执行文件路径,默认 "python3"
PythonExec string `json:"python_exec"`
// Args 传递给脚本的额外命令行参数
Args []string `json:"args"`
// Env 额外的环境变量(会合并到进程环境中)
Env map[string]string `json:"env"`
}
Config Runner 的配置。
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner 管理 Python 子进程的生命周期和通信。
func (*Runner) CloseStdin ¶
CloseStdin 关闭 Python 进程的 stdin,通知 Python 输入结束。 不等待进程退出,由 Python 自行处理剩余数据后退出。
func (*Runner) SetStderrCallback ¶
SetStderrCallback 设置 stderr 日志回调函数。 每当 Python 进程输出一行 stderr 时调用。
Click to show internal directories.
Click to hide internal directories.