public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-x86 commit in dev-python/snakeoil/files: snakeoil-0.4.4-atexit-weakref.patch
@ 2011-11-11 10:41 Brian Harring (ferringb)
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Harring (ferringb) @ 2011-11-11 10:41 UTC (permalink / raw
  To: gentoo-commits

ferringb    11/11/11 10:41:38

  Added:                snakeoil-0.4.4-atexit-weakref.patch
  Log:
  pull in WeakRefFinalizer fix for strongly referenced instances at sys.exit; this primarily helps pkgcore ensuring binpkg caches are flushed on the way out
  
  (Portage version: 2.1.10.19/cvs/Linux x86_64)

Revision  Changes    Path
1.1                  dev-python/snakeoil/files/snakeoil-0.4.4-atexit-weakref.patch

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/snakeoil/files/snakeoil-0.4.4-atexit-weakref.patch?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/snakeoil/files/snakeoil-0.4.4-atexit-weakref.patch?rev=1.1&content-type=text/plain

Index: snakeoil-0.4.4-atexit-weakref.patch
===================================================================
From 2ad8113511381ae502a000809700cb672c073f92 Mon Sep 17 00:00:00 2001
From: Brian Harring <ferringb@gmail.com>
Date: Fri, 11 Nov 2011 02:04:43 -0800
Subject: [PATCH] WeakRefFinalizer: use atexit to cleanup any strongly
 referenced instances at sys.exit

---
 NEWS                 |    4 ++++
 snakeoil/weakrefs.py |   23 ++++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 04015ee..4fbfb0e 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ Snakeoil Release Notes
 ======================
 
 
+* Fix WeakRefFinalizer so that instances that are still strongly referenced
+  at the time of sys.exit have their finalizers ran via atexit.
+
+
 snakeoil 0.4.4: Oct 26th, 2011
 
 * use sane permissions for directories created for tests.
diff --git a/snakeoil/weakrefs.py b/snakeoil/weakrefs.py
index 1a25a9c..272b4d3 100644
--- a/snakeoil/weakrefs.py
+++ b/snakeoil/weakrefs.py
@@ -10,13 +10,15 @@ __all__ = ("WeakValCache", "WeakRefFinalizer")
 # Unused import
 # pylint: disable-msg=W0611
 
+import atexit
+
 try:
     # No name in module
     # pylint: disable-msg=E0611
     from snakeoil._caching import WeakValCache
-    from weakref import ref
+    from weakref import ref, WeakKeyDictionary
 except ImportError:
-    from weakref import WeakValueDictionary as WeakValCache, ref
+    from weakref import WeakValueDictionary as WeakValCache, ref, WeakKeyDictionary
 
 from snakeoil.obj import make_kls, BaseDelayedObject
 from snakeoil.currying import partial
@@ -38,7 +40,6 @@ class WeakRefProxy(BaseDelayedObject):
         obj.__enable_finalization__(weakref)
         return obj
 
-
 def __enable_finalization__(self, weakref):
     # note we directly access the class, to ensure the instance hasn't overshadowed.
     self.__class__.__finalizer_weakrefs__[id(self)] = weakref
@@ -116,6 +117,9 @@ class WeakRefFinalizer(type):
     >>> del obj
     finalization invoked: bar
     """
+
+    __known_classes__ = WeakKeyDictionary()
+
     def __new__(cls, name, bases, d):
         if '__del__' in d:
             d['__finalizer__'] = d.pop("__del__")
@@ -137,6 +141,7 @@ class WeakRefFinalizer(type):
         new_cls = super(WeakRefFinalizer, cls).__new__(cls, name, bases, d)
         new_cls.__proxy_class__ = partial(make_kls(new_cls, WeakRefProxy), cls, lambda x:x)
         new_cls.__proxy_class__.__name__ = name
+        cls.__known_classes__[new_cls] = True
         return new_cls
 
     def __call__(cls, *a, **kw):
@@ -146,3 +151,15 @@ class WeakRefFinalizer(type):
         # weakref registration
         getattr(proxy, '__finalizer__')
         return proxy
+
+    @classmethod
+    def _atexit_cleanup(cls):
+        # cleanup any instances strongly referenced at the time of sys.exit
+        target_classes = cls.__known_classes__.keys()
+        for target_cls in target_classes:
+            for target_ref in target_cls.__finalizer_weakrefs__.values():
+                obj = target_ref()
+                if obj is not None:
+                    obj.__finalizer__()
+
+atexit.register(WeakRefFinalizer._atexit_cleanup)
-- 
1.7.8.rc1







^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] gentoo-x86 commit in dev-python/snakeoil/files: snakeoil-0.4.4-atexit-weakref.patch
@ 2011-12-14 10:31 Brian Harring (ferringb)
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Harring (ferringb) @ 2011-12-14 10:31 UTC (permalink / raw
  To: gentoo-commits

ferringb    11/12/14 10:31:39

  Removed:              snakeoil-0.4.4-atexit-weakref.patch
  Log:
  pull in 0.4.6; clean out old version in the process
  
  (Portage version: 2.1.10.39/cvs/Linux x86_64)



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-12-14 10:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-11 10:41 [gentoo-commits] gentoo-x86 commit in dev-python/snakeoil/files: snakeoil-0.4.4-atexit-weakref.patch Brian Harring (ferringb)
  -- strict thread matches above, loose matches on Subject: below --
2011-12-14 10:31 Brian Harring (ferringb)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox