3 ms·
The multiprocessing module in the standard library is absolutely a Python-native way to do parallelism: with Pool(5) as p: print(p.map(f, [1, 2, 3]
by quacker 6y ago
The multiprocessing module in the standard library is absolutely a Python-native way to do parallelism:
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))
This runs f(1), f(2), and f(3) in parallel, using a pool of five processes.
https://docs.python.org/3.6/library/multiprocessing.html https://docs.python.org/3.6/library/multiprocessing.html
- goostavos 6y agoWhoa! It never occurred to me that `Pool` could be used with context manager. I've always typed out `.close()` manually like a sucker.