I started reading about Async IO in Python, and I found different initialization of the event cycle in different sources in the examples.
One example uses:
await asyncio.gather(
asyncio.create_task(task("One", work_queue)),
asyncio.create_task(task("Two", work_queue)),
)
Another example uses:
ioloop = asyncio.get_event_loop()
tasks = [ioloop.create_task(foo()), ioloop.create_task(bar())]
wait_tasks = asyncio.wait(tasks)
ioloop.run_until_complete(wait_tasks)
It is explained here that gather
is used mainly for high-level manipulation.
As I understood the key concepts in this question are: future objects and low/high-level async/await code.
Judging by the documentation, gather works with the list as a whole.
According to the function asyncio.get_running_loop()
in the documentation, the information is incomprehensible to me.
But I still can't grasp the conceptual difference. Or is it enough to remember that the first option is for simplified tasks, and the second one is for more precise settings?