[Python] ThreadPoolExecutor number of threads

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use the ThreadPoolExecutor in Python using the futures backport package. However, the problem is that all threads are executed at the same time so there is no actual pooling take place. More specifically I get 10 threads of that function instead of 5 and then the others. I use the following code do you find something wrong or it is just the backported implementation? Thank you!

    with ThreadPoolExecutor(max_workers=5) as executor:
    futures = [executor.submit(f, X, y) for t in range(10)]
    for future in as_completed(futures):
    self.trees.append(future.result())

    Continue reading...

Compartilhe esta Página