The run_forever/run_until_complete methods

As the names implies, run_forever causes event_loop to run forever or at least until it's explicitly stopped by calling its stop method. On the other hand, the run_until_complete method causes the loop to keep going until a particular future object is ready to provide a value (refer to the following code example):

The return value of ensure_future is a future object, so you can easily run the scheduler until a particular task is done. The preceding code example runs two coroutines simultaneously as two separate tasks in the same scheduler. The coro1() coroutine contains an infinite loop, so it will ...

Get Daniel Arbuckle’s Mastering Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.