I noticed that there is an existing and much easier solution for my suggestion number 2:
Instead of creating two separate programs and complicatedly sending the data, just fork the process. Sage has the @fork
decorator for this. It even has timeout
argument!
https://doc.sagemath.org/html/en/reference/parallel/sage/parallel/decorate.html
BTW the forum linked above is probably much better suited for solving similar problems with Sage.