|
HOPS
HOPS class reference
|
Pure-C++ (no pybind, no libpython) helper that runs the user's python3 and exchanges JSON with it. This is the interprocess comms primitive used by the no-embed subprocess backends (control-file evaluation and default plotting). One process is spawned per action (no persistent worker!), which is slow and a lot of overhead, but this is ok for a fallback. More...
#include <MHO_PythonSubprocessRunner.hh>
Classes | |
| struct | Result |
Static Public Member Functions | |
| static std::string | ResolveInterpreter () |
| Resolve the python interpreter to use: $HOPS_PYTHON, else "python3" (left for PATH resolution by the shell). More... | |
| static std::string | ResolvePackageDir () |
| Install-prefix-relative directory holding the shipped hops_* python packages, resolved at runtime against GetHopsInstallPrefix() (or $HOPS_INSTALL). Empty if it cannot be determined. More... | |
| static Result | RunModule (const std::string &module, const std::string &request_json) |
Run python -m <module> <request_file>, feeding the JSON request_json via a temp file, and capture stdout/stderr. The child's PYTHONPATH is prepended with ResolvePackageDir() so the shipped hops packages import cleanly. More... | |
Pure-C++ (no pybind, no libpython) helper that runs the user's python3 and exchanges JSON with it. This is the interprocess comms primitive used by the no-embed subprocess backends (control-file evaluation and default plotting). One process is spawned per action (no persistent worker!), which is slow and a lot of overhead, but this is ok for a fallback.
Implementation note: we use popen() (a unidirectional pipe) and pass the JSON request as a temp file given on the child's command line, reading the JSON response back off the child's stdout. This sidesteps the bidirectional-pipe deadlock concerns of a hand-rolled fork/exec while keeping the code small.
Interpreter discovery: $HOPS_PYTHON if set, else "python3" on PATH. Package discovery: the shipped pure-python hops_* packages are located via MHO_DirectoryInterface::GetHopsInstallPrefix() + the install-relative site subdir (baked in as HOPS_PYTHON_SITE_SUBDIR, matching hops_pypath.sh.in), and prepended to the child's PYTHONPATH so the default control/plot entry points are self-contained (no user pip install required).
|
static |
Resolve the python interpreter to use: $HOPS_PYTHON, else "python3" (left for PATH resolution by the shell).
|
static |
Install-prefix-relative directory holding the shipped hops_* python packages, resolved at runtime against GetHopsInstallPrefix() (or $HOPS_INSTALL). Empty if it cannot be determined.
|
static |
Run python -m <module> <request_file>, feeding the JSON request_json via a temp file, and capture stdout/stderr. The child's PYTHONPATH is prepended with ResolvePackageDir() so the shipped hops packages import cleanly.
| module | python module to run with -m (e.g. "hops_control"). |
| request_json | the JSON request payload written to the temp file. |