I want to create many processes, each process runs 5 seconds later than a previous process, namely, the time interval between each process starts is 5 seconds, so that: run process 1 wait 5 seconds run process 2 wait 5 seconds run process 3 wait 5 seconds .....
like:
for i in range(10):
p = multiprocessing.Process(target=func)
p.start()
sleep(5)
#after all child process exit
do_something()
but I want to call do_something() after all the process exit I don't know how to do the synchronization here
with a python pool libary, I can have
pool = multiprocessing.Pool(processes=4)
for i in xrange(500):
pool.apply_async(func, i)
pool.close()
pool.join()
do_something()
but in this way, 4 processes will run simultaneously, I can't decide the time interval between processes, is it possible to create a process pool and then fetch each process, something like
pool = multiprocessing.Pool(processes=4)
for i in xrange(500):
process = pool.fetch_one()
process(func, i)
time.sleep(5)
pool.close()
pool.join()
do_something()
are there such a library or source code snippets which satisfy my needs? thanks