[libvirt] [PATCH] python: virConnect: fix destructor

Eric Blake eblake at redhat.com
Wed Jul 24 21:18:05 UTC 2013


On 06/17/2013 04:40 AM, Sandro Bonazzola wrote:
> Fixed virConnect destructor checking for attribute
> existance before trying to use it.

s/existance/existence/

> Avoids:
> Exception AttributeError: AttributeError("virConnect instance has  no
> attribute 'domainEventCallbacks'",) in <bound method  virConnect.__del__
> of <libvirt.virConnect instance at  0x4280f38>> ignored
> 
> However, something still doesn't work:
> Exception TypeError: TypeError("'NoneType' object is not callable",)
> in <bound method virConnect.__del__ of <libvirt.virConnect object at 0x37576d0>> ignored

Does that mean this patch still needs work?  Is this something we still
need to fix before the 1.1.1 release?

> 
> Signed-off-by: Sandro Bonazzola <sbonazzo at redhat.com>
> ---
>  python/libvirt-override-virConnect.py | 32 +++++++++++++++++---------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py
> index 5495b70..28d6d41 100644
> --- a/python/libvirt-override-virConnect.py
> +++ b/python/libvirt-override-virConnect.py
> @@ -1,11 +1,12 @@
>      def __del__(self):
> -        try:
> -           for cb,opaque in self.domainEventCallbacks.items():
> -               del self.domainEventCallbacks[cb]
> -           del self.domainEventCallbacks
> -           libvirtmod.virConnectDomainEventDeregister(self._o, self)
> -        except AttributeError:
> -           pass
> +        if hasattr(self, 'domainEventCallbacks'):
> +            try:
> +                for cb,opaque in self.domainEventCallbacks.items():
> +                    del self.domainEventCallbacks[cb]
> +                del self.domainEventCallbacks
> +                libvirtmod.virConnectDomainEventDeregister(self._o, self)
> +            except AttributeError:
> +                pass
>  
>          if self._o != None:
>              libvirtmod.virConnectClose(self._o)
> @@ -14,14 +15,15 @@
>      def domainEventDeregister(self, cb):
>          """Removes a Domain Event Callback. De-registering for a
>             domain callback will disable delivery of this event type """
> -        try:
> -            del self.domainEventCallbacks[cb]
> -            if len(self.domainEventCallbacks) == 0:
> -                del self.domainEventCallbacks
> -                ret = libvirtmod.virConnectDomainEventDeregister(self._o, self)
> -                if ret == -1: raise libvirtError ('virConnectDomainEventDeregister() failed', conn=self)
> -        except AttributeError:
> -            pass
> +        if hasattr(self, 'domainEventCallbacks'):
> +            try:
> +                del self.domainEventCallbacks[cb]
> +                if len(self.domainEventCallbacks) == 0:
> +                    del self.domainEventCallbacks
> +                    ret = libvirtmod.virConnectDomainEventDeregister(self._o, self)
> +                    if ret == -1: raise libvirtError ('virConnectDomainEventDeregister() failed', conn=self)
> +            except AttributeError:
> +                pass
>  
>      def domainEventRegister(self, cb, opaque):
>          """Adds a Domain Event Callback. Registering for a domain
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130724/88727b00/attachment-0001.sig>


More information about the libvir-list mailing list