KAutostart and python

This one took me many hours to debug:

For KDE 4 and python there can be a hard to debug problem with KAutostart usage.

Suppose you have a window class

class MyWindow(KDialig, Ui_Dialog):
  def __init__(self):
    self.kas = KAutostart('myapp')
    self.kas.setAutostarts(True)

You may find that the setAutostarts() doesn’t actually work. This is because MyWindow references kas and kas references MyWindow (as the parent object) (or the application – I’m not sure). The problem is that KAutostart() stores the information when it is deleted (in it’s destructor) and since it is never deleted it won’t store anything.

You need to understand that the destructors won’t be called even when the program exits, because of the circular reference.

To solve the problem call:

self.kas=None

at some point.

Have a look here for more on python and its destructors.