title: Integrating OCaml in python - How to hold an ocaml session from python?
body: <p>I would like a python GUI to have an OCaml process in the background. I would like to keep a single session throughout the program's lifetime, and depending on user inputs, call some OCaml commands and retrieve OCaml's output. Some OCaml variables and structures may be defined along the way so I would like to maintain a single ongoing session.</p>
  
  <p>My solution was to hold an OCaml toplevel process using popen and interact with its stdin and stdout. This works purely for me for several reasons:
  1. I don't know when is the OCaml calculation done and can't tell if it's output is complete or there is more to come (especially so if the evaluation takes some time, and if multiple OCaml commands were invoked).
  2. I have no inherent way of telling whether the OCaml command ran smoothly or maybe there were OCaml warnings or errors.
  3. I lose the structure of OCaml's output. For example, if the output spreads over several lines, I can't tell which lines were broken due to line size, and which were originally separate lines. </p>
  
  <p>I know there are some discussions and some packages for combining python with OCaml, but they all run python commands from OCaml, and I need the opposite. </p>