import time import joblib 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() joblib.Parallel(n_jobs=5, backend="loky", verbose=20)( joblib.delayed(f)(_) for _ in [5, 5, 5, 5, 5] ) print("Total time cost: {} sec!".format(time.time() - t_start))