3

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.

honeybadger
  • 1,465
  • 1
  • 19
  • 32
  • 1
    Does this answer your question? [Printed output not displayed when using joblib in jupyter notebook](https://stackoverflow.com/questions/55955330/printed-output-not-displayed-when-using-joblib-in-jupyter-notebook) – char Apr 29 '20 at 06:45

1 Answers1

-3
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]
imrankhan
  • 11
  • 1