Python subprocess Popen periodic callback
Write a function that runs the following loop;
- launches
curl
in a subprocess and processes the returned JSON. - If the sim should terminate, it writes the required file and returns.
- Otherwise
sleep
for 4.5 minutes.
Start that function in a threading.Thread
before you launch the simulation.
You'd have to test what happens to your for line in p.stdout
loop if the program running in p
exits.
Maybe it will generate an exception. Or you might want to check p.poll()
in the loop to handle that gracefully.