python async operation over list element

Viewed 27

I have to iterate over a list and get some data. I have thought to make the loop async but I think it is not working.

async def my_check_on_list_element(ele):
  code


a_list = ["a", "b", "c", "d"]

for i in a_list:
  my_check_on_list_element(i)
   

I think I miss something, but I don't see what.

1 Answers
import asyncio

a_list = ["a", "b", "c", "d"]


def process_the_list():
    for item in a_list:
        print(item)


loop = asyncio.get_event_loop()
loop.run_in_executor(None, process_the_list)
Related