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]: 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/ in () /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