Mike Bayer avatar Mike Bayer committed abc8f4e

- added a little more checking for garbage-collection dereferences in
InstanceState.__cleanup() to reduce "gc ignored" errors on app
shutdown

Comments (0)

Files changed (2)

   - 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

lib/sqlalchemy/orm/attributes.py

         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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.