I have created a dictionary in my Python application where I save the data and I have two tasks that run concurrently and get data from external APIs. Once they get the data, they update the dictionary - each with a different key in the dictionary.
I want to understand if the dictionary is async safe or do I need to put a lock when the dictionary is read/updated?
The tasks also read the last saved value each time.
my_data = {}
asyncio.create_task(call_func_one_coroutine)
asyncio.create_task(call_func_two_coroutine)
async def call_func_one_coroutine():
data = await goto_api_get_data()
my_data['one'] = data + my_data['one']
async def call_func_two_coroutine():
data = await goto_api_another_get_data()
my_data['two'] = data + my_data['two']