I'm using joblib
to parallelize my python 3.5 code.
If I do:
from modules import f
from joblib import Parallel, delayed
if __name__ == '__main__':
Parallel( n_jobs = n_jobs,backend = "multiprocessing")(delayed(f)(i) for i in range( 10 ))
code doesn't work. Instead:
from joblib import Parallel, delayed
def f( i ):
# my func ...
if __name__ == '__main__':
Parallel( n_jobs = n_jobs, backend = "multiprocessing")(delayed(f)(i) for i in range(10))
This works!
Can someone explain why I have to put all my functions in the same script?
That is really unpractical, because in modules there are plenty of functions that I coded, that I don't want to copy / paste in the main script.