简体   繁体   中英

Print the output of a function in joblib

I am trying to use joblib to parallelize a loop that runs over a function. I want the intermediate print commands of the function to be displayed, not just the return value of the function.

from joblib import Parallel, delayed

def dummy(i):
    print("the value passed is",i)

Parallel(n_jobs=2)(delayed(dummy)(i) for i in range(0,5,1))

I get the following output:

[None,
 None,
 None,
 None,
 None]

I want to get the following output (or something similar):

[the value passed is 0,
the value passed is 1,
the value passed is 2,
the value passed is 3,
the value passed is 4]

Edit: I just noticed that it does indeed print my required output in the terminal window from which my Jupyter notebook is launched. Any ideas on how to actually print it in my notebook. Thanks in advance.

将您的i参数放入函数虚拟Parallel(n_jobs=2)(delayed(dummy(i)) for i in range(0,5,1))

from joblib import Parallel, delayed def dummy(i): return "the value passed is " + str(i) Parallel(n_jobs=2)(delayed(dummy)(i) for i in range(0,5,1))

output::

[the value passed is 0,
the value passed is 1,
the value passed is 2,
the value passed is 3,
the value passed is 4]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM