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 
33 {
34  public:
35  struct Result
36  {
37  bool spawned = false;
38  bool exited = false;
39  int exit_code = -1;
40  std::string out;
41  std::string err;
42 
44  bool Success() const { return spawned && exited && exit_code == 0; }
45  };
46 
51  static std::string ResolveInterpreter();
52 
58  static std::string ResolvePackageDir();
59 
71  static Result RunModule(const std::string& module, const std::string& request_json);
72 };
73 
74 } // namespace hops
75 
76 #endif
Pure-C++ (no pybind, no libpython) helper that runs the user's python3 and exchanges JSON with it....
Definition: MHO_PythonSubprocessRunner.hh:33
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>, 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:36
std::string err
captured stderr (python traceback, if any)
Definition: MHO_PythonSubprocessRunner.hh:41
std::string out
captured stdout (the JSON response)
Definition: MHO_PythonSubprocessRunner.hh:40
bool exited
did the child exit normally (vs. signalled)
Definition: MHO_PythonSubprocessRunner.hh:38
bool spawned
did popen() launch a shell/interpreter at all
Definition: MHO_PythonSubprocessRunner.hh:37
bool Success() const
Definition: MHO_PythonSubprocessRunner.hh:44
int exit_code
child exit status when exited == true
Definition: MHO_PythonSubprocessRunner.hh:39