New submission from Sarbjit singh: I have written a python tkinter code using threads so as the tkinter wizard updates automatically by tkinter mainloop running in the main thread and background process running in separate thread. But I noticed, that python crashes after some time when running the code. Moreover its random in nature but python crashes most of the time. I have written a small test code which can show this problem (My original code is similar to this but having some real processes and many other features, so I am sharing the test code).
###################################################################### # Test Code for Tkinter with threads import Tkinter import threading import Queue import time # Data Generator which will generate Data def GenerateData(q): for i in range(1000000): #print "Generating Some Data, Iteration %s" %(i) time.sleep(0.01) q.put("Some Data from iteration %s. Putting this data in the queue for testing" %(i)) # Queue which will be used for storing Data q = Queue.Queue() def QueueHandler(widinst, q): linecount = 0 while True: print "Running" if not q.empty(): str = q.get() linecount = linecount + 1 widinst.configure(state="normal") str = str + "\n" widinst.insert("end", str) if linecount > 100: widinst.delete('1.0', '2.0') linecount = linecount - 1 widinst.see('end') widinst.configure(state="disabled") # Create a thread and run GUI & QueueHadnler in it tk = Tkinter.Tk() scrollbar = Tkinter.Scrollbar(tk) scrollbar.pack(side='right', fill='y' ) text_wid = Tkinter.Text(tk,yscrollcommand=scrollbar.set) text_wid.pack() t1 = threading.Thread(target=GenerateData, args=(q,)) t2 = threading.Thread(target=QueueHandler, args=(text_wid,q)) t2.start() t1.start() tk.mainloop() ###################################################################### TO REPRODUCE: If you open this code in IDLE and run it, it will sometimes appeared to be in hang state. So to reproduce, modify the sleep time to 0.1 from 0.01 and run it. After this stop the application, and modify it back to 0.01, do save and run it. This time it will run and after some time, python will stop working. I am using windows 7 (64 bit). NOTE: I am getting different stack trace's when it crashes on console: Please refer to the attached file for the stack traces. ---------- components: Tkinter files: debugstack.txt messages: 178642 nosy: Sarbjit.singh priority: normal severity: normal status: open title: Python crashes on running tkinter code with threads type: crash versions: Python 2.7 Added file: http://bugs.python.org/file28503/debugstack.txt _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16823> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com