Is there any way to stop first thread when the second thread is finished?
Example:
from functools import partial
import threading
def run_in_threads(*functions):
threads=[]
for function in functions:
thread=threading.Thread(target=function)
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
def __print_infinite_loop(value):
while True:print(value)
def __print_my_value_n_times(value,n):
for i in range(n):print(value)
if __name__=="__main__":
run_in_threads(partial(__print_infinite_loop,"xyz"),partial(__print_my_value_n_times,"123",1000))))))
In above axample i run in threads two functions and I have to stop the first thread when the second is finished. I read that it supports by events, but unfortunatly I did not use it yet.
You could use a
threading.Eventlike this: