import time from multiprocessing import Pool def f(duration=5): """ this function will keep working for ``duration`` seconds """ a = 0 t0 = time.time() while time.time() - t0 < duration: a += 1 return if __name__ == '__main__': t_start = time.time() # using ``with ... as ...`` clause helps avoid ``Pool.close`` after the context with Pool(5) as p: p.map(f, [5, 5, 5, 5, 5]) print("Total time cost: {} sec!".format(time.time() - t_start))