I have 3 folders, namely, 1, 2, 3 each with the following executable. How can I run all of them concurrently at once?
exec(open("Test.py").read())
I have 3 folders, namely, 1, 2, 3 each with the following executable. How can I run all of them concurrently at once?
exec(open("Test.py").read())
Since you want to run these .py files as separate processes, you should be able to execute them via the same python executable your main script is using. Use Popen to start all of the processes and then wait on them in turn.
#!/usr/bin/env python3
import os
import sys
import subprocess as subp
folder_names = ["1", "2", "3"]
procs = [subp.Popen([sys.executable, os.path.join(folder, "Test.py"])
for folder in folder_names]
for proc in procs:
return_code = proc.wait()
1,2,3.chmod +x myfile.py. For windows, as long as .py is associated with python, it'll work). Then, put it somewhere in the operating system PATH so you can execute it from anywhere.