I'm trying to run some multiprocessing in a Jupyter notebook, using python version 3.7.0. However, even a really simple example seems to hang indefinitely. After reading this answer I tried explicitly calling .close and .join on the pool, but it still hangs. Example code is below, can anyone tell me what's wrong?
import multiprocessing as mp
def fun(x):
return 2*x
with mp.Pool() as pool:
args = list(range(10))
res = pool.map(fun, args)
pool.close()
pool.join()
multiprocessing
has problems working in an interactive prompt. save your code as a .py file, and run it with the python interpreter. (it can be made to work, but it's much simpler to just run the file rather than execute code interactively) – Sobelfun
in an external file, for example,workers.py
in the same directory as your ipynb file and then addfrom workers import fun
. In other words, worker functions need to be imported. – Outsoar