GNOME Bugzilla – Bug 107697
gtk.Widget subclass object destroyed prematurely
Last modified: 2004-12-22 21:47:04 UTC
This bug is present in pygtk-1.99.14, but does not appear to be present in pygtk-1.99.10, and I'm not sure about anything in between. In certain conditions, an instance of a class that inherits from a gtk widget can be garbage collected (in python, not gtk) while the object is still active and still required. The following conditions must exist (I think) for this to occur: 1. The class inherits from a gtk.Widget subclass. 2. There are references, in python, to the instance of the class, but it is displayed on the screen. 3. The instance has connected one of its signals to a method of itself (e.g. self.connect('clicked', self._on_clicked)). 4. A cyclic garbage collection run has occurred. I will attach a simplified example that demonstrates the error. Workaround: If the current code looks like this: class MyButton(gtk.Button): def __init__(self, *args): gtk.Button.__init__(self, *args) self.connect('clicked', self.on_clicked) def on_clicked(self, widget): ... Replace with this: class MyButton(gtk.Button): def __init__(self, *args): gtk.Button.__init__(self, *args) self.connect('clicked', self.__class__.on_clicked) def on_clicked(self): ... Relying on the fact the the first argument to a handler is the widget, which in this case is the same as 'self'.
Created attachment 14808 [details] Simplified example of the described problem
This is a duplicate (hopefully I can get the bug fixed for 1.99.16) *** This bug has been marked as a duplicate of 92955 ***