我正在尝试使用joblib
来并行化运行在一个函数上的循环。我希望显示功能的中间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))
我得到以下输出:
[None,
None,
None,
None,
None]
我想得到以下输出(或类似的东西):
[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]
编辑:
我只是注意到它确实在启动Jupyter笔记本的终端窗口中打印了我所需的输出。关于如何在笔记本中实际print
的任何想法。
预先感谢。
答案 0 :(得分:1)
将您的i参数放入功能虚拟Parallel(n_jobs=2)(delayed(dummy(i)) for i in range(0,5,1))
答案 1 :(得分:0)
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))
输出::
[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]