M
M
motya882020-12-24 15:46:10
Python
motya88, 2020-12-24 15:46:10

How to interrupt a thread in python?

Good afternoon. Tell me how to stop the creation of new threads if at the time of the X thread the length of the list2 list has become> 0?

from multiprocessing.pool import ThreadPool

list_1=[1,2,3,4,5]
list2 =[]

def srch_1(ppp):
    # тут некая логика при которой я добавляю запись в list2


p1 = ThreadPool(10)
for ppp in list_1:
    p1.apply_async(srch_1, args=(ppp,))

p1.close()
p1.join()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
milssky, 2020-12-24
@milssky

break on the desired condition does not work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question