example_joblib.py 454 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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))