You can make this amount without multiprocessing at all, and it might be easier, if not faster, to just use generators.
# prepare a generator of generators each at 1000 point intervals >>> xr = (xrange(1000*i+1,i*1000+1001) for i in xrange(10000000)) >>> list(xr)[:3] [xrange(1, 1001), xrange(1001, 2001), xrange(2001, 3001)]
However, if you want to use multiprocessing , you can also do this. I use the multiprocessing fork, which is better at serialization (but otherwise, not quite different).
>>> xr = (xrange(1000*i+1,i*1000+1001) for i in xrange(10000000)) >>> import pathos >>> mmap = pathos.multiprocessing.ProcessingPool().map >>> tmap = pathos.multiprocessing.ThreadingPool().map >>> sum(tmap(sum, mmap(lambda x:x, xr))) 50000000005000000000L
The w / o multiprocessing version is faster and takes about a minute on my laptop. The multiprocessing version takes a few minutes due to the overhead of creating many python processes.
If you're interested, get pathos here: https://github.com/uqfoundation
source share