[Repoze-checkins] r1138 - in repoze.zope2/trunk: . repoze/zope2 repoze/zope2/tests

Chris McDonough chrism at agendaless.com
Thu Jun 26 17:03:36 EDT 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Thu Jun 26 17:03:36 2008
New Revision: 1138

Log:
  - Make disable_gc only happen at initialization.  Drool.



Modified:
   repoze.zope2/trunk/CHANGES.txt
   repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py
   repoze.zope2/trunk/repoze/zope2/z2bob.py
   repoze.zope2/trunk/setup.py

Modified: repoze.zope2/trunk/CHANGES.txt
==============================================================================
--- repoze.zope2/trunk/CHANGES.txt	(original)
+++ repoze.zope2/trunk/CHANGES.txt	Thu Jun 26 17:03:36 2008
@@ -1,3 +1,7 @@
+0.4.5 (2008-06-26)
+
+  - Make disable_gc only happen at initialization.  Drool.
+
 0.4.4 (2008-06-25)
 
   - Add a configuration flag for the app:zope2 section: 'disable_gc'.

Modified: repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/tests/test_z2bob.py	Thu Jun 26 17:03:36 2008
@@ -96,6 +96,22 @@
         from repoze.zope2.z2bob import cleanPath
         self.assertEqual(cleanPath('foo/../bar'), ['bar'])
 
+    def test_initialize_gcdisable(self):
+        from repoze.zope2 import z2bob
+        reenable = False
+        import gc
+        if gc.isenabled():
+            reenable = True
+        try:
+            old = z2bob.db
+            z2bob.db = True
+            z2bob.initialize(disable_gc='true')
+            self.failIf(gc.isenabled())
+        finally:
+            z2bob.db = old
+            if reenable:
+                gc.enable()
+
 class TestZope2ObobHelper(unittest.TestCase, PlacelessSetup):
     def setUp(self):
         PlacelessSetup.setUp(self)
@@ -127,28 +143,16 @@
         helper = self._makeOne(environ)
         self.assertEqual(helper.environ, environ)
         self.assertEqual(helper.encoding, 'utf-8')
-        self.assertEqual(helper.zopeconf, None)
         self.assertEqual(helper.appname, 'Application')
         self.assertEqual(helper.browser_default_redirects, False)
 
     def test_ctor_nondefaults(self):
         environ = {}
-        import gc
-        if gc.isenabled():
-            reenable = True
-        else:
-            reenable = False
-        try:
-            helper = self._makeOne(environ, appname='Application2',
-                                   browser_default_redirects='true',
-                                   disable_gc='true')
-            self.assertEqual(helper.appname, 'Application2')
-            self.assertEqual(helper.browser_default_redirects, True)
-            self.assertEqual(gc.isenabled(), False)
-        finally:
-            if reenable:
-                gc.enable()
-        
+        helper = self._makeOne(environ, appname='Application2',
+                               browser_default_redirects='true',
+                               disable_gc='true')
+        self.assertEqual(helper.appname, 'Application2')
+        self.assertEqual(helper.browser_default_redirects, True)
 
     def test_setup(self):
         from zope.security.management import queryInteraction

Modified: repoze.zope2/trunk/repoze/zope2/z2bob.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/z2bob.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/z2bob.py	Thu Jun 26 17:03:36 2008
@@ -152,14 +152,9 @@
     def _configure(self, config):
         self._config = config
         self.encoding = config.get('encoding', 'utf-8')
-        self.zopeconf = config['zope.conf']
         self.appname = config.get('appname', 'Application')
         self.browser_default_redirects = asbool(config.get(
             'browser_default_redirects', False))
-        # XXX hack for disable_gc: should be at higher level
-        if asbool(config.get('disable_gc', False)):
-            import gc
-            gc.disable()
 
     def __del__(self):
         if tm and not tm.isActive(self.environ):
@@ -225,16 +220,26 @@
         if self.request is not None:
             # if there was not an error during setup()
             self.request.close()
-        # be explicit about clearing out references; if we hang around
+        # It's very important to call noSecurityManager() here;
+        # otherwise we'll leak as many references to AccessControl
+        # SecurityManager objects as there are threads in the WSGI
+        # server's worker thread pool.  These will hold references to
+        # aq-wrapped user objects, which in turn hold references to
+        # "the world".  It doesn't matter that we also call
+        # noSecurityManager in setup() because that might be in a
+        # different thread and we really need to clear *this* thread's
+        # security manager now to avoid a leak.  In fact, the call in
+        # setup() is probably voodoo.
+        noSecurityManager() 
+        # Be explicit about clearing out references; if we hang around
         # for some reason, we don't want our subitems hanging around.
+        # But we can't yet get rid of environ or conn as they're used
+        # in __del__ :-(
         self.request = None
         self.user_folders = None
         self.vroot_stack = None
-        self.request = None
         self.root = None
         self.browser_default_published = None
-        # can't get rid of environ or conn as they're used in __del__
-        noSecurityManager()
 
     def next_name(self):
         trns = self.request['TraversalRequestNameStack']
@@ -676,6 +681,10 @@
             db = getDB(config)
         finally:
             lock.release()
+    # XXX hack for disable_gc: should be at higher level
+    if asbool(config.get('disable_gc', False)):
+        import gc
+        gc.disable()
 
 def get_root(helper):
     if db is None:

Modified: repoze.zope2/trunk/setup.py
==============================================================================
--- repoze.zope2/trunk/setup.py	(original)
+++ repoze.zope2/trunk/setup.py	Thu Jun 26 17:03:36 2008
@@ -12,7 +12,7 @@
 #
 ##############################################################################
 
-__version__ = '0.4.4'
+__version__ = '0.4.5'
 
 from ez_setup import use_setuptools
 use_setuptools()


More information about the Repoze-checkins mailing list