0

I am trying to run multiple python scripts in parallel with subprocess in a linux OS

Similar to this: Running multiple commands from multiple terminal windows from python script

Here is what I tried:

subprocess.call(['gnome-terminal', '-e', "python3 ab.py"]) subprocess.call(['gnome-terminal', '-e', "python3 bc.py"]) subprocess.call(['gnome-terminal', '-e', "python3 cd.py"]) 

Unfortunately, the terminal flashes in split seconds and disappears. Any reason for this? adding shell=True makes the terminal stays but does not execute the script.

1

2 Answers 2

3

subprocess.run should work:

subprocess.Popen(['gnome-terminal', '-e', "python3", "ab.py"], shell=True) subprocess.Popen(['gnome-terminal', '-e', "python3", "bc.py"], shell=True) subprocess.Popen(['gnome-terminal', '-e', "python3", "cd.py"], shell=True) 

Edit:

os.system("gnome-terminal -x python ab.py") 
14
  • It does this same. what could be the issue?CommentedAug 30, 2021 at 7:22
  • it doesnt. it shows the shell and then the script did not run. I dont know whats wrongCommentedAug 30, 2021 at 7:38
  • I tried with the shell=True. The terminal stays but does not run the python script. Any thoughts around this?CommentedAug 30, 2021 at 7:47
  • @JA-pythonista I edited with 4 elements in a list, did you see that edit?CommentedAug 30, 2021 at 7:48
  • Yes, I did. It opens the terminal and does nothingCommentedAug 30, 2021 at 7:50
0

Do you need to split all parts of the command line into separate strings?

subprocess.call(['gnome-terminal', '-e', "python3", "ab.py"]) 

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.