python stop infinite thread loop

Solutions on MaxInterview for python stop infinite thread loop by the best coders in the world

showing results for - "python stop infinite thread loop"
Angela
24 Oct 2019
1# specific problem and answer
2import threading
3import tkinter
4
5def Loop(run):
6	while run():
7		# infinite loop
8
9run = True
10main = tkinter.Tk()
11threading.Thread(target=Loop, args=(lambda:run,)).start()
12main.mainloop()
13run = False # thread will be stopped after Tkinter GUI closed
14			# or use other trigger
15
16# alternatively, you might want to read about daemon instead