How to connect to a GObject signal in python, without it keeping a reference to the connecter?
问题 The problem is basically this, in python's gobject and gtk bindings. Assume we have a class that binds to a signal when constructed: class ClipboardMonitor (object): def __init__(self): clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) clip.connect("owner-change", self._clipboard_changed) The problem is now that, no instance of ClipboardMonitor will ever die . The gtk clipboard is an application-wide object, and connecting to it keeps a reference to the object, since we use the callback