How can I run a program hundreds of times using Python?
I have a program which I need to call more than 100 times with different values.
I want to do it simultaneously that is not wait for one call to complete and then to start again.
How can I achieve it ?
Is multithreading the solution to it.
I am using python for it.
You can do this with the subprocess module. Here is an example that runs the sleep command a hundred times, with a sleep value between 0 and 10 seconds. It runs them all in parallel and then exits when they all finish.
import subprocess import time bin_path = 'sleep' invocation_args = [[str(x*0.1)] for x in range(0,100)] subprocs =  for args in invocation_args: subprocs.append(subprocess.Popen([bin_path] + args)) while len(subprocs) > 0: subprocs = [p for p in subprocs if p.poll() is None] time.sleep(0.05) print 'Finished running all subprocs'