backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 07 Jul 2010 13:01:44 +0200
changeset 5920 6c0a7a881024
parent 5919 2f3cf2b4ec0d (current diff)
parent 5906 d40ced753291 (diff)
child 5921 b3fcb004d0e1
backport stable
server/repository.py
server/session.py
--- a/pytestconf.py	Wed Jul 07 13:01:25 2010 +0200
+++ b/pytestconf.py	Wed Jul 07 13:01:44 2010 +0200
@@ -40,7 +40,7 @@
 
 def clean_repo_test_cls(cls):
     if 'repo' in cls.__dict__:
-        if not cls.repo._shutting_down:
+        if not cls.repo.shutting_down:
             cls.repo.shutdown()
         del cls.repo
     for clsattr in ('cnx', '_orig_cnx', 'config', '_config', 'vreg', 'schema'):
--- a/server/repository.py	Wed Jul 07 13:01:25 2010 +0200
+++ b/server/repository.py	Wed Jul 07 13:01:44 2010 +0200
@@ -125,6 +125,8 @@
         # sources
         self.sources = []
         self.sources_by_uri = {}
+        # shutdown flag
+        self.shutting_down = False
         # FIXME: store additional sources info in the system database ?
         # FIXME: sources should be ordered (add_entity priority)
         for uri, source_config in config.sources().items():
@@ -210,7 +212,6 @@
         for i in xrange(config['connections-pool-size']):
             self.pools.append(pool.ConnectionsPool(self.sources))
             self._available_pools.put_nowait(self.pools[-1])
-        self._shutting_down = False
         if config.quick_start:
             config.init_cubes(self.get_cubes())
         self.hm = hook.HooksManager(self.vreg)
@@ -317,8 +318,8 @@
         """called on server stop event to properly close opened sessions and
         connections
         """
-        assert not self._shutting_down, 'already shutting down'
-        self._shutting_down = True
+        assert not self.shutting_down, 'already shutting down'
+        self.shutting_down = True
         self.system_source.shutdown()
         if isinstance(self._looping_tasks, tuple): # if tasks have been started
             for looptask in self._looping_tasks:
@@ -794,7 +795,7 @@
     def _get_session(self, sessionid, setpool=False, txid=None,
                      checkshuttingdown=True):
         """return the user associated to the given session identifier"""
-        if checkshuttingdown and self._shutting_down:
+        if checkshuttingdown and self.shutting_down:
             raise Exception('Repository is shutting down')
         try:
             session = self._sessions[sessionid]
--- a/server/session.py	Wed Jul 07 13:01:25 2010 +0200
+++ b/server/session.py	Wed Jul 07 13:01:44 2010 +0200
@@ -1025,6 +1025,14 @@
         self.cnxtype = 'inmemory'
         self.disable_hook_categories('integrity')
 
+    @property
+    def pool(self):
+        """connections pool, set according to transaction mode for each query"""
+        if self.repo.shutting_down:
+            self.reset_pool(True)
+            raise Exception('repository is shutting down')
+        return getattr(self._threaddata, 'pool', None)
+
 
 class InternalManager(object):
     """a manager user with all access rights used internally for task such as