[libvirt] ruby-libvirt issue

Paweł Krześniak pawel.krzesniak at gmail.com
Wed Nov 24 15:32:11 UTC 2010


On Tue, Nov 23, 2010 at 14:28, Chris Lalancette <clalance at redhat.com> wrote:
> In terms of making this automatically happen during connection closing, I'm
> not entirely sure what we can (and should) do.  I guess we could keep some sort
> of list of objects that "depend" on this connection object, and then during
> connection close  free them all up. Does anyone know how the python bindings
> handle this?

python bindings work more or less the same way (see attachment).

So conclusion is, that all objects must be free() before closing connection.
It's not so intuitive, so maybe info about that should be somewhere in docs?

-- 
Pawel
-------------- next part --------------
In [1]: import libvirt, os, gc

In [2]: 

In [3]: # testcase 1

In [4]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
0
Out[4]: 256

In [5]: c = libvirt.open('qemu:///system')

In [6]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
1
Out[6]: 0

In [7]: c.close()
Out[7]: 0

In [8]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
0
Out[8]: 256

In [9]: 

In [10]: # work's OK (and ruby binding works the same way)

In [11]: 

In [12]: # testcase 2

In [13]: c = libvirt.open('qemu:///system')

In [14]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
1
Out[14]: 0

In [15]: d = c.lookupByName("t1")

In [16]: d
Out[16]: <libvirt.virDomain instance at 0x95ef4cc>

In [17]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
1
Out[17]: 0

In [18]: c.close()
Out[18]: 1

In [19]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
1
Out[19]: 0

In [20]: c._o is None
Out[20]: True

In [21]: d.connect()._o is None
Out[21]: True

In [22]: d._conn._o is None
Out[22]: True

In [23]: d.create()
Out[23]: 0

In [24]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
1
Out[24]: 0

In [25]: d=None

In [26]: c.close()
libvir: error : invalid connection pointer in virConnectClose
---------------------------------------------------------------------------
libvirtError                              Traceback (most recent call last)

/home/imo/src/libvirt/python/<ipython console> in <module>()

/home/imo/src/libvirt/python/libvirt.pyc in close(self)
   1330         ret = libvirtmod.virConnectClose(self._o)
   1331         self._o = None
-> 1332         if ret == -1: raise libvirtError ('virConnectClose() failed', conn=self)
   1333         return ret
   1334 

libvirtError: invalid connection pointer in virConnectClose

In [27]: c=None

In [28]: gc.collect()
Out[28]: 24

In [29]: os.system("netstat -na|grep -v LISTENING |grep -c libvirt-sock")
1
Out[29]: 0



More information about the libvir-list mailing list