Re: [PATCH] python: virConnect: fix destructor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]