Python/Tkinter/tk crash [long]

Eric Brunel eric.brunel at pragmadev.com
Mon Aug 18 12:13:57 CEST 2003


Pedro Rodriguez wrote:
> On Thu, 14 Aug 2003 09:10:22 +0000, Eric Brunel wrote:
> 
> 
>>Hi all,
>>
>>I was creating a Tkinter widget in the style of the reversed tabs below Excel 
>>worksheets and I stepped in a serious problem: the code I made makes python 
>>crash with a seg fault, bus error or X11 BadGC error on both Solaris (2.6 and 
>>2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I tried to simplify 
>>the script, but I couldn't reproduce the crash with a simpler code. So the code 
>>below is somewhat long; sorry for that.
>>
>>To make it crash, just run the script and click on a tab. It usually crashes at 
>>the first click, but you may have to play a bit with the tabs. I tried to run 
>>Python through gdb to see where the crash happens, but it seems to be quite 
>>random. Maybe a memory corruption?
>>
>>There's a simple workaround, but with drawbacks: at the beginning of the 
>>__update method, if I do not destroy and re-create the Canvas, but simply empty 
>>its contents, the script works. But it keeps the commands declared created at 
>>the tcl level for the former bindings, so it silently eats up memory.
>>
> 
> 
> As far as I understand, the __changeTab method is called when an event
> occurs on the __tabsCanvas. But one of the first actions of the __update
> method (which is called by __changeTab) is to destroy the __tabsCanvas
> object. 
> 
> So DURING the callback call you are destroying the object to which the
> callback is bound. I wonder if this is the cause of the blow up at the
> return of the callback (it may depend on how  the memory is reallocated
> on different systems).

In fact, you're absolutely right, but it still shouldn't result in a crash. I 
also discovered that the problem only happens with ButtonRelease events, and not 
ButtonPress ones. Apparently, the tcl interpreter doesn't properly remembers 
that the pointer on the canvas shouldn't be freed until the binding is 
completely executed.

I've reported the problem to the comp.lang.tcl newsgroup. I hope they'll have a 
solution for it, because I can't figure out by myself what I should do to 
prevent the crash (I'm not that familiar with the code for tcl/tk). For the 
moment, I'll use bindings on ButtonPress's rather than ButtonRelease's.

Thanks a lot to all who answered anyway!
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list