I am using multiprocessing.dummy.Pool . I create a single thread pool at the module level, and then use pool.apply_async(requests.get, [params]) to run the task.
This command gives me a future that I can add to the list with other futures indefinitely, until I want to collect all or some of the results.
multiprocessing.dummy.Pool - against all logic and reason - the THREAD pool, not the process pool.
Example (works on both Python 2 and 3 if queries are installed):
from multiprocessing.dummy import Pool import requests pool = Pool(10)
Requests will be executed simultaneously, so running all ten of these requests will take no more than the longest. This strategy will use only one CPU core, but this should not be a problem, because almost all the time will be spent waiting for I / O.
Andrew Gorcester
source share