0

I have a Python module `mymodule'

# mymodule.py
import multiprocessing as mp

def do_work(x):
  # do some stuff
  return 42+x

def work():
  pool = mp.Pool()
  work_list= [1,2,3,4,5]
  returned_values = pool.map(do_work, work_list)
  pool.close()

#end mymodule

I want to import this interactively in a Python shell and invoke work() like this

 In [1]: import mymodule as mm
 In [2]: mm.work()

If I do this the do_work does not seem to be doing anything. How can I make this work in an interactive shell. If I turn the above into a non-interactive script I face no problems. I am on Windows.

san
  • 4,144
  • 6
  • 32
  • 50
  • You'll need to provide a [mcve], because this code doesn't work (`do_work` needs to accept an argument) and it also doesn't do anything (e.g. print any output) and if I fix those problems then it works fine in a console. – Alex Hall May 29 '18 at 10:49
  • @AlexHall Changed the code to make do_work to do something minimal. It doesn't work on Ipython QtConsole. Are you on Windows too ? – san May 29 '18 at 10:52
  • The main issue is that the multiprocessing module can't find your function, look at the linked question for more info – Wolph May 29 '18 at 10:54

0 Answers0