from time import perf_counter, sleep
import threading
def foo(bar):
some_func(bar) # takes longer with higher values of bar
if __name__ == "__main__":
threads = []
for i in range(15):
threads.append(threading.Thread(target=func, args=(i,)))
for i in range(15):
threads[i].start()
for i in range(15):
threads[i].join()
if sum_condition: # condition is from user input, so no way of knowing when it'll be true
# kill all threads/join all threads
pass
I don't know how to join all the threads when the condition is met, and the function some_func
is from a library, so I cannot exit out of it. Is there any way to join all these threads/stop the function so the threads can return?