I am trying to run code at the same time in Spyder, that I would have previously ran by opening new consoles and playing each script individually. However, I would like these to run all at the same time. My first .py file sends code to a robot, the second receives almost real time data from the robot and populates a .csv file, and the third .py file plots a live graph based on data on the .csv file.
I have tried using
import subprocess
process1 = subprocess.Popen(["python", "pop.py"]) # Create and launch process pop.py using python interpreter
process2 = subprocess.Popen(["python", "pop1.py"])
process3 = subprocess.Popen(["python", "pop2.py"])
process1.wait() # Wait for process1 to finish (basically wait for script to finish)
process2.wait()
process3.wait()
Run multiple python file concurrently
However, I have no way to stop the .csv file from stopping to receive data, and the third .py file doesn't run, i.e the plot doesn't run.
Thanks for any advice, Lauren
threadingmodule if all your scripts are quite light to run. If one or two are heavy,multiprocessingmight be better. You don't want to join the threads/processes as that waits for an individual script to finish, instead you could have a loop withtime.sleep()to keep the main thread constantly running.