multiprocessing - how to fetch process from python process pool -


i want create many processes, each process runs 5 seconds later previous process, namely, time interval between each process starts 5 seconds, that: run process 1 wait 5 seconds run process 2 wait 5 seconds run process 3 wait 5 seconds .....

like:

        in range(10):             p = multiprocessing.process(target=func)             p.start()             sleep(5)         #after child process exit         do_something() 

but want call do_something() after process exit don't know how synchronization here

with python pool libary, can have

    pool = multiprocessing.pool(processes=4)     in xrange(500):             pool.apply_async(func, i)     pool.close()     pool.join()     do_something() 

but in way, 4 processes run simultaneously, can't decide time interval between processes, possible create process pool , fetch each process, like

pool = multiprocessing.pool(processes=4) in xrange(500):     process = pool.fetch_one()     process(func, i)     time.sleep(5) pool.close() pool.join() do_something() 

are there such library or source code snippets satisfy needs? thanks

just put suggestions together, like:

plist = [] in range(10):     p = multiprocessing.process(target=func)     p.start()     plist.append(p)     sleep(5) p in plist:     p.join() do_something() 

you give timeout argument join() in order handle stuck processes; in case you'd have keep iterating through list, removing terminated processes until list empty.


Comments