I was going through the Python documentation for asyncio and I'm wondering why most examples use loop.run_until_complete() as opposed to Asyncio.ensure_future().
For example: https://docs.python.org/dev/library/asyncio-task.html
It seems ensure_future would be a much better way to demonstrate the advantages of non-blocking functions. run_until_complete on the other hand, blocks the loop like synchronous functions do.
This makes me feel like I should be using run_until_complete instead of a combination of ensure_futurewith loop.run_forever() to run multiple co-routines concurrently.
run_until_completedoesn't block anything. The difference between it andrun_foreveris that the loop pauses at the completion of the coroutine. The only time it will block is if your coroutine never awaits.do_other_things()doesn't execute untildo_io()is done, even thoughdo_io()awaits a the sleep.loop.create_task(do_other_things())before you callrun_forever.