Aiohttp async

t0 = time.time ()

loop = asyncio.get_event_loop()
loop.run_until_complete(fetch(BASE_URL+"/43_43074/", callback=parse_url))
tasks = [fetch(BASE_URL + page_url, callback=parse_body, title=title) for title, page_url in TITLE2URL.items()]
loop.run_until_complete(asyncio.gather(*tasks[:500]))
loop.close()
elapsed = time.time() - t0
print("cost {}".format(elapsed))

what"s the difference between loop.run_until_complete (asyncio.gather (* tasks [: 500]) and loop.run_until_complete here?
and an await? what"s the difference?

Mar.20,2021

1. Each thread has an event loop. When the main thread calls asyncio.get_event_loop, an event loop is created. You need to throw the asynchronous task to the loop's run_until_complete method, and the event loop will arrange the execution of the co-program. As with the method name, the asynchronous task completion method is executed.
2.await is to coordinate the execution of those Synchronize tasks until they are completed.

Menu