1

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

LaurenMcG
  • 11
  • 3
  • Please specify Python version. – Konrad Talik Sep 15 '20 at 10:58
  • Have a look into the `threading` module if all your scripts are quite light to run. If one or two are heavy, `multiprocessing` might 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 with `time.sleep()` to keep the main thread constantly running. – Peter Sep 15 '20 at 11:02
  • I think you can use python file1.py & python file2.py and so on in terminal to run them parallel. – Deepak Tripathi Sep 15 '20 at 11:07

0 Answers0