[Python] asyncio - wait for each task in a dynamic list to finish or be cancelled

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of asyncio tasks: [task1, task2, task3]. And each task can append more tasks to this list, e.g., task3 might append task4.

    How can I wait for all tasks in this dynamic list to finish or be cancelled?

    I tried await asyncio.gather(*[task1, task2, task3]), but it doesn't wait for tasks created by task1, task2 or task3.

    Continue reading...

Compartilhe esta Página