Answers for "python stop infinite thread loop"

0

python stop infinite thread loop

# specific problem and answer
import threading
import tkinter

def Loop(run):
	while run():
		# infinite loop

run = True
main = tkinter.Tk()
threading.Thread(target=Loop, args=(lambda:run,)).start()
main.mainloop()
run = False # thread will be stopped after Tkinter GUI closed
			# or use other trigger

# alternatively, you might want to read about daemon instead
Posted by: Guest on April-27-2021

Python Answers by Framework

Browse Popular Code Answers by Language