HOPS
HOPS class reference
MHO_PythonSubprocessRunner.hh
Go to the documentation of this file.
1 #ifndef MHO_PythonSubprocessRunner_HH__
2 #define MHO_PythonSubprocessRunner_HH__
3 
4 #include <string>
5 
6 namespace hops
7 {
8 
37 {
38  public:
39  struct Result
40  {
41  bool spawned = false;
42  bool exited = false;
43  int exit_code = -1;
44  std::string out;
45  std::string err;
46 
48  bool Success() const { return spawned && exited && exit_code == 0; }
49  };
50 
55  static std::string ResolveInterpreter();
56 
62  static std::string ResolvePackageDir();
63 
76  static Result RunModule(const std::string& module, const std::string& request_json);
77 };
78 
79 } // namespace hops
80 
81 #endif
Pure-C++ (no pybind, no libpython) helper that runs the user's python3 and exchanges JSON with it....
Definition: MHO_PythonSubprocessRunner.hh:37
static std::string ResolveInterpreter()
Resolve the python interpreter to use: $HOPS_PYTHON, else "python3" (left for PATH resolution by the ...
Definition: MHO_PythonSubprocessRunner.cc:18
static Result RunModule(const std::string &module, const std::string &request_json)
Run python -m <module> <request_file> <response_file>, feeding the JSON request_json via a temp file ...
Definition: MHO_PythonSubprocessRunner.cc:172
static std::string ResolvePackageDir()
Install-prefix-relative directory holding the shipped hops_* python packages, resolved at runtime aga...
Definition: MHO_PythonSubprocessRunner.cc:30
Definition: MHO_AdhocFlagging.hh:18
Definition: MHO_PythonSubprocessRunner.hh:40
std::string err
captured stderr (python traceback, if any)
Definition: MHO_PythonSubprocessRunner.hh:45
std::string out
the JSON response (read from the child's response file)
Definition: MHO_PythonSubprocessRunner.hh:44
bool exited
did the child exit normally (vs. signalled)
Definition: MHO_PythonSubprocessRunner.hh:42
bool spawned
did popen() launch a shell/interpreter at all
Definition: MHO_PythonSubprocessRunner.hh:41
bool Success() const
Definition: MHO_PythonSubprocessRunner.hh:48
int exit_code
child exit status when exited == true
Definition: MHO_PythonSubprocessRunner.hh:43