0

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())
2
  • You want to run them all within the master python file? Or should they be separate processes? Commented Sep 17, 2022 at 4:51
  • I want to run them separately. It's the same file name but in different folders. Commented Sep 17, 2022 at 4:55

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Where should I save this file? I don't want to put in the folders: 1,2,3.
Ideally you'd make it an executable (I added a "shebang" for unix like operating systems - plus you'd do 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.