How can I run multiple python scripts? At the moment I run one like so python script1.py
.
I've tried python script1.py script2.py
and that doesn't work: only the first script is run. Also, I've tried using a single file like this;
import script1
import script2
python script1.py
python script2.py
However this doesn't work either.
With Bash:
That's the entire script. It will run the two Python scripts at the same time.
Python could do the same thing itself but it would take a lot more typing and is a bad choice for the problem at hand.
I think it's possible though that you are taking the wrong approach to solving your problem, and I'd like to hear what you're getting at.
The simplest solution to run two Python processes concurrently is to run them from a bash file, and tell each process to go into the background with the
&
shell operator.For a more controlled way to run many processes in parallel, look into the Supervisor project, or use the multiprocessing module to orchestrate from inside Python.
I am working in Windows 7 with Python IDLE. I have two programs,
and
I open up IDLE and then open file progA.py. I run the program, and when prompted for input I enter
"b" + <Enter>
and then"c" + <Enter>
I am looking at this window:
Next, I go back to Windows Start and open up IDLE again, this time opening file progB.py. I run the program, and when prompted for input I enter
"x" + <Enter>
and then"y" + <Enter>
I am looking at this window:
Now two IDLE Python 3.6.3 Shell programs are running at the same time, one shell running progA while the other one is running progB.