I am getting a series of warnings that occurs during interpreter shutdown of a Python 2.7 script when using libvirt. This is reproducible on a variety of distros including python2-libvirt 3.7.0-1 on Fedora 27 to libvirt-python 3.2.0-1 on Centos 7.4.1708. The warnings I get when the script is exitings is:
Exception AttributeError: "'NoneType' object has no attribute 'virDomainFree'" in <bound method virDomain.__del__ of <libvirt.virDomain object at 0x7f34a194ee10>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'virDomainFree'" in <bound method virDomain.__del__ of <libvirt.virDomain object at 0x7f34a194ed90>> ignored
Exception AttributeError: "'NoneType' object has no attribute 'virConnectClose'" in <bound method virConnect.__del__ of <libvirt.virConnect object at 0x7f34a176a590>> ignored
Drilling down into the library, it seems to be an issue with assumptions in destructor order as in this code from libvirt.py:
class virDomain(object):
def __del__(self):
if self._o is not None:
libvirtmod.virDomainFree(self._o)
self._o = None
libvirtmod
is a global created by an import at the top of the libvirt.py module. When the __del__()
destructor for virDomain
is finally run, libvirtmod
has been replaced by the value None
causing the code above to fail with a warning. We have been using this Python module for some time now, but only recently have these warning started showing up after we refactored the code quite heavily. What can I do to suppress these warnings from standard error or avoid the situation from occurring? Is there a way to ensure objects from libvirt.py are cleaned up before libvirtmod.so goes away?
We test on a variety of distros and would like to stick with using the stock (but updated) packages that come with the distro.