H
H
Hz An2017-09-22 10:37:59
Python
Hz An, 2017-09-22 10:37:59

How to limit the number of threads in Python?

Has a loop that currently creates a new thread for each element from the array:

for base in core_bases:
    name_thread = "thread %s " % (item_lst + 1)
    thread = CoreCheck(base, name_thread)
    thread.start()
    time.sleep(0.2)

How can we implement, let's say, a limit of 100 threads, clog 100 threads with a cycle, and if it is released, let's say 5th thread so that data processing occupies it, and so on.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JaxxDexx, 2017-09-22
@maffiozi

Use a Pool
Instead of a process pool, you can use a thread pool:
from multiprocessing.pool import ThreadPool

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question