0

I have a python script myscript that when run it "stays open" with a GUI. I would like to write a python script launching myscript two times like this:

bash>python runNTimes.py 2

I have the following code for runNTimes.py

import subprocess
for i in range(int(sys.argv[1])):
    subprocess.call(['python', 'myscript.py'])

The problem is that this happens synchronously, i.e. once I launch the first in a subprocess the second subprocess is not launched until the first terminates.

A minimal example for myscript.py:

try: 
        import Tkinter as tk # for Python2
except: 
        import tkinter as tk # for Python3

win=tk.Tk()
win.mainloop()
2
  • Call blocks, use Popen Commented Jul 16, 2016 at 14:56
  • @PadraicCunningham You beat my ninja edit Commented Jul 16, 2016 at 15:06

1 Answer 1

1

Use Popen instead: call() blocks Popen() doesn't

from subprocess import Popen
import sys
for i in range(int(sys.argv[1])):
    Popen(['python', 'synccall1.py'])

synccall1.py

try: 
        import Tkinter as tk # for Python2
except: 
        import tkinter as tk # for Python3

win=tk.Tk()
win.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

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.