I am new to multiprocessing and need some help in understanding on how I can convert my current code to use multiprocessing so it can process data faster. I have the below data
accounts = [{'Id': '123', 'Email': 'Test_01@gmail.com', 'Status': 'ACTIVE'},
{'Id': '124', 'Email': 'Test_02@gmail.com', 'Status': 'ACTIVE'},
{'Id': '125', 'Email': 'Test_03@gmail.com', 'Status': 'ACTIVE'}]
which I need to process, currently I am using for loop to process it works perfectly fine but takes longer which is what I would like to optimize, the code looks as follows -
dl_users = {}
group_users = {}
for a in accounts:
if a['Status'] == 'ACTIVE':
dl_users[a['Email']] = get_dl_users(a['Email'])
group_users[a['Email']] = get_group_users(a['Id'])
print(dl_users)
print(group_users)
Instead of using for loop I would like to populate dl_users
and group_users
data in parallel so when the data is in large quantity it can be processed quickly, I saw a couple of examples and tried using concurrent lib but due to lack of knowledge on multiprocessing, I have been struggling any help/guidance would greatly be appreciated.