1

I am new to Multiprocessing and I am trying to run the basic first example here on Jupyter notebook and it never stops. I've copied the code below:

from multiprocessing import Pool

def f(x):
    return x*x

if __name__ == '__main__':
    with Pool(5) as p:
        print(p.map(f, [1, 2, 3]))

I have even tried rewriting it like this: enter image description here

I run jupyter notebook from Anaconda Navigator on Windows 7

Any guidance would be really appreciated

Max
  • 13
  • 4
  • Please edit the question to include the code you're running, not the example given in the documentation, because they are different. – Ruzihm Sep 20 '18 at 21:35
  • Try calling your code from the terminal instead. This looks like an issue with the Jupyter and IDLE interpreters. – jarcobi889 Sep 20 '18 at 22:08

1 Answers1

0

I have failed to replicate the issue after several attempts with your code and the code from the first example, found on the page you've linked to. The code runs smoothly, stops completely after running the code and this is returned to me:

CPU Time: 0.09 sec(s), Memory: 14548 kilobyte(s)

Worker processes within a Pool will live for the complete duration of the Pool’s work queue. Hence the difficulty and queue of your code are next to nothing, the processes should kill themselves within seconds.

As you are news to Multiprocessing, I'll just repeat the basic methods used, which are:

  • Start() starts the process's activity.
  • Join() waits for the workers' processes to exit.
  • Close() will prevent any more tasks from being submitted to the pool and exit once all tasks complete.
  • Terminate() will just exit by stopping all worker processes immediately.

When one is not working with a Pool, one must always call close() or terminate() before using join(), but that is not relevant for your question. I simply can't see how or why your program shouldn't stop running. I will, however, suggest trying another compiler - maybe even another online compiler like jdoodle.com to see what kind of result it returns when you execute your code.


Edit: Hence the fact, that there is an edge at the bottom of the box on your picture, I'd say that the process has finished. How do you know, that your code won't stop running?

  • Good observation on it completing. @Max Take a look at the answer to this question: https://stackoverflow.com/questions/29629103/simple-python-multiprocessing-function-doesnt-output-results – Ruzihm Sep 20 '18 at 22:00
  • I am able to replicate in Python's Idle editor, but once I run it from the terminal, it performs correctly. Likely is a Jupyter interpreter error. – jarcobi889 Sep 20 '18 at 22:07