I am trying to write my first piece of asynchronous code. I've simplified my use-case down and have two scripts - 'main' and 's3_accessor'. The main script builds out a list of values that I then want to pass to the 'build_inventory' function.
The list has hundreds of values, so synchronous processing is slow.
main.py
import s3_accessor # another .py script
import asynchio
async def main():
some_list [a, b, c, d, e, f, g]
for val in some_list:
inventory_df = s3_accessor.build_inventory(val)
s3_accessor.write_df_to_s3('some_key', inventory_df)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
s3_accessor.py
async def build_inventory(val):
...
Question:
How would I modify this code to make it such that the iteration over the list is asynchronous?
I tried wrapping the entire for loop section in await asyncio.wait() but that doesn't appear to be the correct approach.
build_inventoryare running simultaneously? Is it okay if multiple copies ofwrite_df_to_s3are running simultaneously?