[libvirt] [RFC] domain-events-python

Daniel Veillard veillard at redhat.com
Wed Oct 29 13:21:45 UTC 2008

On Wed, Oct 29, 2008 at 07:45:26AM -0400, Ben Guthro wrote:
> One issue that I seem to be running into for both dom, and conn objects is the creation of a python object from the C vir{Connect,Domain}Ptr
> The issue is that when creating a python object, and passing "_obj" into the constructor - it will give a different python object each time, instead of searching for an existing object, and bumping the ref count.
> For example - each time the C callback would be called, we would create a new python object with the came "._o", rather than getting a new reference to a common one
> This is not an issue unless we want to store data in the python object independent from C object (like the python callback list)
> So...we could create a hash/dict object of virConnect objects...but when would you know to delete the last reference?

  Yes, the .o trick cmes from libxml2 python bindings where i used
the same thing. This can be a bit confusing, but as you noted we don't
really found a good workaround to the refcounting problem otherwise.
  I guess it's fine to implement it that way, if not perfect, and if
some Python guru come with a solution, well we don't expect the user
code to use the ._o directly so we should be able to change the way
we do the mapping without disturbing the python applications.

  The connection object could be stored though since the
function will need a connection, there in the python bindings we can
save a reference to that object and bring it when we get an event.
But for Domains, yes we will duplicate objects :-\


Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

More information about the libvir-list mailing list