I have a fixed number of API endpoints (4 for example) that all do the same thing. I would like to multiprocess a loop that can asynchronously send data to the endpoints. However, I want to make sure that each endpoint only sees one request at a time. Is there a way to do this using the multiprocessing tool in python. Perhaps it would look something like,
import pandas as pd
from multiprocessing import Pool
def process_data(data, endpoint):
...
endpoint_lst = [
'https://endpoint1',
'https://endpoint2',
'https://endpoint3',
'https://endpoint4'
]
df = pd.read_csv('datafile.csv')
with Pool(processes=len(endpoint_lst)) as p:
p.starmap(process_data, [df.iteritems(), endpoint_lst])