[Python] Why do most asyncio examples use loop.run_until_complete()?

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página