I have a peculiar python problem. During the course of execution of my gtk python application, some of my class objects mysteriously lose attributes, causing some of the functionality of my program to break.
It's hard to give a sense of why this might happen - I never intentionally delete attributes, and the classes in question inherit from a class I wrote myself (and no others).
I can trigger the problem by doing a certain action repeatedly (for example generating many calls to the add_card
method - either by clicking madly or by opening a file, causing add_card
to be called twenty or so times)
I am really at a loss, and I wish I had more information I thought useful to give you.
What can cause a python object to lose attributes?
EDIT, Re. Questions:
Here are example tracebacks related to the two attributes I 'lose':
Traceback (most recent call last):
File "lib/genericlist.py", line 90, in cursor_changed
if self.viewer:
AttributeError: 'DeckerRunnerList' object has no attribute 'viewer'
Traceback (most recent call last):
File "lib/genericlist.py", line 100, in row_activated
selection = self.TABLE_NAME+"&&"+text
AttributeError: 'DeckerRunnerList' object has no attribute 'TABLE_NAME'
And here is where they are set:
class DeckerGenericList(object):
def __init__(self, database, viewer=None, deck=None):
super(DeckerGenericList, self).__init__()
self.database = database
self.viewer = viewer
self.deck = deck
#TABLE_NAME is set in the subclass constructor
This particular subclass doesen't call it's superclass __init__
so the attribute sets are duplicated in the subclass:
class DeckerRunnerList(DeckerGenericList):
def __init__(self, database, viewer=None, deck=None):
self.database = database
self.viewer = viewer
self.deck = deck
self.TABLE_NAME = "runners"
All the other subclasses of DeckerGenericList have the same issue, and they are all defined like this:
class DeckerGearList(DeckerGenericList):
def __init__(self, database, viewer=None, deck=None):
self.TABLE_NAME = "gear"
#... some other class attributes
super(DeckerGearList, self).__init__(database, viewer=viewer, deck=deck)