type
methods
py |
Create a new |
---|---|
pyDefine |
Define a variable to be available to python code running in the session. |
pyEval |
Evalue the given python statement in the session, and return the result. |
pyExec |
Execute the given python code in the session and return the python session. |
pyInit |
Initialize the python session by calling the given func to do any one-time setup of the python session. |
pyTimeout |
Set the timeout for |
Slot Details
py
@Axon { admin=true }
static PySession py(Dict? opts := null)
Create a new PySession
instance. Options:
image
: name of the Docker image to run. By default, the lib will try to run the following images in this order:ghcr.io/haxall/hxpy:<ver>
(where ver = current library Haxall version)ghcr.io/haxall/hxpy:latest
ghcr.io/haxall/hxpy:main
network
: the name of the Docker network you want the container to join.logLevel
: log level of the hxpy python process in Docker. Valid values areWARN
,INFO
,DEBUG
, (default='WARN')
The default timeout for pyEval()
is 5min. Use pyTimeout()
to change this timeout.
Sessions created in the context of a task are persistent, meaning they will not be closed until the task is killed.
pyDefine
pyEval
pyExec
@Axon { admin=true }
static PySession pyExec(PySession py, Str code)
Execute the given python code in the session and return the python session. Note: python exec()
does not return a value, so use pyEval()
if you need the result of running a python statement. This method is primarily useful for declaring functions that you want available when using pyEval()
.
pyInit
@Axon { admin=true }
static PySession pyInit(PySession py, Fn fn)
Initialize the python session by calling the given func to do any one-time setup of the python session. If pyInit()
has already been called on this session, then the callback is not invoked.
Typically, this func is used in the context of a task since the python session in a task is persistent. This allows to do any one-time pyExec()
or pyDefine()
when the task is first creatd.