5 ms·
If you’re looking for simple threaded multiprocessing, it’s not that hard/painful: from multiprocessing.dummy import Pool pool = Pool(num_threads)
by bobwaycott 9y ago
If you’re looking for simple threaded multiprocessing, it’s not that hard/painful:
from multiprocessing.dummy import Pool
pool = Pool(num_threads)
result = pool.map(your_func, your_objects)
pool.close()
pool.join()
Improve and/or complicate things from there.
- zeptomu 9y agoThis is a nice pattern and there are surprisingly many problems that can be solved that way. AFAIK you do not have to join() here as the processes die after the map call. Often the challenge is a big amount of (hopefully read-only) data that you want to access in every 'your_func'. The naive solution is to copy the data, but this might blow your memory.