How do I run several independent processes in parallel when the argument is the same? My current (not nice) solution is:
import time
import multiprocessing
def parse_args():
...
return args
def my_function(args):
...
if __name__ == '__main__':
args = parse_args()
processes = []
for i in range(5):
processes.append(multiprocessing.Process(target=my_function, args=(args,)))
processes[-1].start()
time.sleep(200)
for i in range(5):
processes[i].terminate()
Also, my_function runs infinetely and it doesn't return anything.
my_functionto quit gracefully rather thanterminate-ing it, but if there's no specific need to gracefully shut down, there's no problem with that. Amultiprocessing.Poolwould just add lots of overhead and complexity you don't seem to be using anyway.