0

I'm trying to learn the multiprocessing module of Python (3). I've encountered the following really simple example while googling, but for me it just speeds up the processors (I can see them on task manager/hear the fan), but nothing happens whatsoever, it just gets stuck. (yes, the computer should be fast enough...)

I've been looking for syntax examples, to figure out what I may be doing wrong, without success. Does anyone know what I may be missing on the code/syntax to produce any results? Tx!

import multiprocessing as mp

def cube(x):
    return x**3

pool = mp.Pool(processes=4)
results = pool.map(cube, range(1,7))
print(results)
Adam
  • 322
  • 4
  • 12
  • 1
    From the multiprocessing module documentation: "Functionality within this package requires that the __main__ module be importable by the children.". If you look at the [very first example](https://docs.python.org/3.4/library/multiprocessing.html), you'll see there's a line there ` if \_\_name\_\_ == '\_\_main\_\_':`. You'll need that. –  Sep 08 '15 at 09:38
  • 1
    Related: http://stackoverflow.com/questions/2697640/multiprocessing-bomb/2697679 (and I think it's also a dupe, but I can't find that). Apparently, with the if-statement and under Windows, you get an endless number of processes. –  Sep 08 '15 at 09:41
  • Thanks @Evert, that was it... – Adam Sep 08 '15 at 10:05

0 Answers0