On Qui, 2007-09-06 at 00:41 +0200, Sebastian Pölsterl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi! > > I'm working on Deskbar-Appplet and ran into some problems using the > beagle handler. I discussed it thoroughly with the beagle maintainers > and it doesn't seem to be their fault, because the same code worked before. > > What happens is: > I query beagle async like that: > <code> > def query(self, qstring): > beagle_query = beagle.Query() > beagle_query.add_text(qstring) > beagle_query.connect("hits-added", self.hits_added_cb, qstring) > self.beagle.send_request_async(beagle_query) > </code> > So the beagle_query variable is local. > > The problem is that way I don't receive any results. Further > investigation revealed that the connection from beagle to deskbar is > closed before the results can be transmitted. > > If I use self.beagle_query instead of beagle_query it works fine. > > My assumption is that the garbage collector collects beagle_query at the > end of the method. If beagle wants to send its results it can't find the > object anymore, because it has been collected. > Whereas with self.beagle_query the object doesn't get collected and > everything works fine.
I also think your assumption is right. beagle_query, as a free variable, is unref'ed by python as soon as the method goes out of scope, while self.beagle_query remains referenced from the class instance and so the GObject wrapped by self.beagle_query is not unreffed. Why did it work in PyGObject < 2.11? Probably because before wrapped GObjects did not _usually_ get immediately collected by python, and so the likely reference counting bug towards the BeagleQuery GObject was not noticed. Although I believe that even before there was still a small change that the query GObject would still be collected before time. If my theory is correct then this only means that PyGObject 2.11 only uncovered a bug that also existed before, but which out of luck hardly ever manifested itself. > > Please be aware that this is just an assumption, but if I'm right _and_ > you can fix that bug I would be enormously happy. I really suspect that there is something wrong with the beagle bindings. beagle_send_request_async should probably be g_object_ref'ing the beagle_query object, and unref it later after the response is received and after calling the async handler. I hope this helps. -- Gustavo J. A. M. Carneiro <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> "The universe is always one step beyond logic" -- Frank Herbert _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/