summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <nicholson@endlessm.com>2016-12-21 12:02:14 -0600
committerSimon Feltman <s.feltman@gmail.com>2016-12-21 20:46:54 -0800
commit8694e4dd42565f07b6f9ba1221fb03146be333a0 (patch)
tree685e09fd3c612410341e7fc82e0fb609c23d0c83
parent54c623ba639654716ca475f75c92cc8ed673d9f5 (diff)
downloadpygobject-8694e4dd42565f07b6f9ba1221fb03146be333a0.tar.gz
Handle exception unreffing Variant at exit
Calling unref will cause gi and gi.repository.GLib to be imported. However, if the program is exiting, then these modules have likely been removed from sys.modules and will raise an exception. Assume that's the case for ImportError and ignore the exception since everything will be cleaned up, anyways. This can be triggered with the following trivial program: $ python3 -c 'from gi.repository import GLib; v = GLib.Variant("s", "foo")' Exception ignored in: Adding some debug code to show the full exception revealed this: Traceback (most recent call last): File "/home/dan/src/pygobject/build3/gi/overrides/GLib.py", line 265, in __del__ self.unref() ImportError: import of 'gi.repository.GLib' halted; None in sys.modules https://bugzilla.gnome.org/show_bug.cgi?id=776092
-rw-r--r--gi/overrides/GLib.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 5a7792df..82010c07 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -251,7 +251,16 @@ class Variant(GLib.Variant):
return GLib.Variant.new_tuple(elements)
def __del__(self):
- self.unref()
+ try:
+ self.unref()
+ except ImportError:
+ # Calling unref will cause gi and gi.repository.GLib to be
+ # imported. However, if the program is exiting, then these
+ # modules have likely been removed from sys.modules and will
+ # raise an exception. Assume that's the case for ImportError
+ # and ignore the exception since everything will be cleaned
+ # up, anyways.
+ pass
def __str__(self):
return self.print_(True)