]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added a little more checking for garbage-collection dereferences in
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Nov 2007 17:31:09 +0000 (17:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Nov 2007 17:31:09 +0000 (17:31 +0000)
InstanceState.__cleanup() to reduce "gc ignored" errors on app
shutdown

CHANGES
lib/sqlalchemy/orm/attributes.py

diff --git a/CHANGES b/CHANGES
index 0018b8389358c3baa3ab4b565ac7fb11127e4a54..653d58a22f923abbbd60b08f6e5649554746c240 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -107,7 +107,11 @@ CHANGES
   - fixed error where Query.add_column() would not accept a class-bound
     attribute as an argument; Query also raises an error if an invalid
     argument was sent to add_column() (at instances() time) [ticket:858]
-        
+
+  - added a little more checking for garbage-collection dereferences in
+    InstanceState.__cleanup() to reduce "gc ignored" errors on app
+    shutdown
+    
   - The session API has been solidified:
 
     - It's an error to session.save() an object which is already
index 6cf2b74e97496f5f9a156cd9fcd50856034679af..27f4b017c30d16128034d7a0fa2d67e82c9c01ee 100644 (file)
@@ -557,19 +557,25 @@ class InstanceState(object):
         self.instance_dict = None
         
     def __cleanup(self, ref):
-        if self.instance_dict is None or self.instance_dict() is None:
+        # tiptoe around Python GC unpredictableness
+        instance_dict = self.instance_dict
+        if instance_dict is None:
             return
             
-        instance_dict = self.instance_dict()
-        
+        instance_dict = instance_dict()
+        if instance_dict is None:
+            return
+
         # the mutexing here is based on the assumption that gc.collect()
         # may be firing off cleanup handlers in a different thread than that
         # which is normally operating upon the instance dict.
         instance_dict._mutex.acquire()
         try:
             # if instance_dict de-refed us, or it called our
-            # _resurrect, return
-            if self.instance_dict is None or self.instance_dict() is None or self.obj() is not None:
+            # _resurrect, return.  again setting local copy
+            # to avoid the rug being pulled in between
+            id2 = self.instance_dict
+            if id2 is None or id2() is None or self.obj() is not None:
                 return
                 
             self.__resurrect(instance_dict)