I have recently started using multithreading to be able to, for example, supply input during a for loop. This was successfull but I wanted to try more. When I tried threading in combination with Tkinter things went wrong. So for my example I have a very simple piece code (Python 2.7.11). I realize it beats the point of threading but it shows my problem:
import Tkinter
import threading
def func():
root=Tkinter.Tk() #Open Tkinter window
Tkinter.mainloop()
root.quit() #Extra quit, although it doesn't seem to help
thread1=threading.Thread(target=func)
thread1.start()
thread1.join() #Wait for thread to end (for me to close the window)
del thread1 #Extra deletes (although they don't seem to help)
del func
Running this code once works fine. The Tkinter window opens, I close it manually and the rest works fine. However if I run it again the interpreter freezes. If a second thread, or a simple loose print statement, is added it doesn't even start those. The entire enterpreter freezes and I can only re-run this code by restarting the Kernel. So do I have to quit the thread/Tkinter in a special way to prevent this from happening?
Additional information: My CPU usage goes way up. When running it the 2nd time task manager shows up to 30% CPU usage. So I guess there is an infinite loop going on somewhere. I have read that Tkinter does not take threading well, but I have seen instances where this workes. What I have here is a very simple thing so it must be something I am doing wrong. Hopefully someone can help me, because I couldn't find an answer in whatever way I tried to Google it.
Thanks in advance.