Very Strange Program Crashes
over 9 years agoSo I ran into a problem with my code that was causing crashes that gave no error messages. This was very frustrating because I had no idea where to start actually looking up info on what might be causing the crash.
Here's what was happening: My 'logbox,' which is where the log text is displayed as it gets processed, seemed to be causing crashes when particularly large log files (10k+) were opened. I did not actually test this much on medium-sized logfiles, but kept using the 10k file in my tests because it was really good at producing the crash. This crash sometimes happened and sometimes didn't happen.
The code that actually processes the log lines is executed in a separate thread, which then tells the GUI to display the line after it has been processed.
A couple days passed without me doing much work - I was discouraged and worried that tkinter may just have limitations that won't allow logfiles that big to work with the program.
I randomly did a search on 'tkinter limitations' and got this page, which had a few interesting points. But the jackpot was in section 10.7.1...
"If you do use threads in Tkinter programs, however, only the main thread (the one that built the GUI and started the mainloop) can make GUI calls. Things like the update method described in the preceding section cannot be called from spawned threads in a GUI programthey'll likely trigger very strange program crashes."
A-HA!
Time to restructure part of my app... Again :P
Comments
Also, and I am sure you've heard this before, think really really hard for alternatives before using threads. Threads are great... but it's also very easy to get random deadlocks or crashes... that are difficult to debug.