I would like to do something like this:
import MyProcess
proc1 = MyProcess('python').start()
proc2 = MyProcess('bash').start()
### This would mimic what happens in a python shell
print(proc1('a=10')) ==> ___
print(proc1('a*2')) ==> 20
proc1('b=a*2')
print(proc1("print(b)") ==> 20
### This would mimic what happens in a bash shell
proc2("a=hello")
proc2("b=there")
c = proc2("echo \"$a $b\"")
print(c) ==> hello there
proc1.stop()
proc2.stop()
I'm not really sure where to start. I tried using subprocess
but as soon as a read back the stdout
from my last command (issued with process.stdin.write
, the process seems to quit and won't execute any further commands. Also, multiprocessing might be better as it can make better use of resources like multiple cores.
I can't find any examples of multiprocessing where you start a process, issue a command, get the output, issue another command, get that output, etc. It seems like it's always about starting the process and then letting it finish. Would I need the process to wrap some kind of while True
loop?