简体   繁体   English

在 joblib 中打印函数的输出

[英]Print the output of a function in joblib

I am trying to use joblib to parallelize a loop that runs over a function.我正在尝试使用joblib来并行化在函数上运行的循环。 I want the intermediate print commands of the function to be displayed, not just the return value of the function.我希望显示函数的中间print命令,而不仅仅是函数的return值。

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.编辑:我刚刚注意到它确实在启动我的 Jupyter 笔记本的终端窗口中打印了我需要的输出。 Any ideas on how to actually print it in my notebook.关于如何在我的笔记本中实际print它的任何想法。 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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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