[Python] How can I wait for any one thread out of several to finish?

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

  1. Stack

    Stack Membro Participativo

    Say I want to launch multiple threads to perform tasks, and as they finish I want to process their work units. And optionally launch more threads to do more work units.

    Is there any standard way to tell Python that I want to wait for any one of my threads to complete? Bonus points if it's easy to know which one.

    Googling the question produced no useful results. All the answers were how to wait for all the threads, or how to wait for the first thread. Neither of these are what I'm looking for.

    I've toyed with using a counting semaphore, but is there a better way?

    Continue reading...

Compartilhe esta Página