Python/Python__works

async, loop 등등

말하는감자 2020. 2. 13. 17:55
import asyncio
import nest_asyncio


def loof_test():
  test_list = [1,2,3,4,5]
  nest_asyncio.apply() 
  loop = asyncio.get_event_loop()
  loop_list = loop.run_until_cimplete(futures(test_list))
  for _ in loop_list:
  	print(_)
  
 @asyncio.coroutine
 async def futures(test_list):
 	futures = [asyncio.ensure_future(async_main(t, ) for t in test_list]
    result = await asyncio.gather(*futures)
    return result
 
 
 @asyncio.coroutine
 async def async_main(t):
 	return t