Re:Parallelising Python with Threading and Multiprocessing
by canjobear on Saturday May 03, 2014 @03:22PM
(#7692048)
To take advantage of process level parallelism you still have to have a pickle-able function, i.e. defined at the top level in a module.
[ Parent
| on HN ]
Re:Parallelising Python with Threading and Multiprocessing
by e12e on Saturday May 03, 2014 @08:13PM
(#7692821)
Good point. Just a couple of points on futures: 1) they're backported to python 2[1], and 2) to make the example work, you need a pickleable function as you say, for example, if you have ipython running in a virtualenv:
import pip
pip.main(["install","futures"])
import random
def l(_):
return random.random()
with f.ProcessPoolExecutor(max_workers=4) as ex:
out_list = list(ex.map(l, range(1000)))
len(out_list)
#> 1000
[1] https://pypi.python.org/pypi/futures