server/session.py
changeset 8808 538852f69b48
parent 8807 d9aaad2c52e9
child 8809 9ee4d0c65ad2
equal deleted inserted replaced
8807:d9aaad2c52e9 8808:538852f69b48
   895     def cnxset(self):
   895     def cnxset(self):
   896         """connections set, set according to transaction mode for each query"""
   896         """connections set, set according to transaction mode for each query"""
   897         if self._closed:
   897         if self._closed:
   898             self.free_cnxset(True)
   898             self.free_cnxset(True)
   899             raise Exception('try to access connections set on a closed session %s' % self.id)
   899             raise Exception('try to access connections set on a closed session %s' % self.id)
   900         return getattr(self._tx, 'cnxset', None)
   900         return self._tx.cnxset
   901 
   901 
   902     def set_cnxset(self):
   902     def set_cnxset(self):
   903         """the session need a connections set to execute some queries"""
   903         """the session need a connections set to execute some queries"""
   904         with self._lock:
   904         with self._lock:
   905             if self._closed:
   905             if self._closed:
   936 
   936 
   937     def free_cnxset(self, ignoremode=False):
   937     def free_cnxset(self, ignoremode=False):
   938         """the session is no longer using its connections set, at least for some time"""
   938         """the session is no longer using its connections set, at least for some time"""
   939         # cnxset may be none if no operation has been done since last commit
   939         # cnxset may be none if no operation has been done since last commit
   940         # or rollback
   940         # or rollback
   941         cnxset = getattr(self._tx, 'cnxset', None)
   941         cnxset = self._tx.cnxset
   942         if cnxset is not None and (ignoremode or self.mode == 'read'):
   942         if cnxset is not None and (ignoremode or self.mode == 'read'):
   943             # even in read mode, we must release the current transaction
   943             # even in read mode, we must release the current transaction
   944             self._free_thread_cnxset(threading.currentThread(), cnxset)
   944             self._free_thread_cnxset(threading.currentThread(), cnxset)
   945             del self._tx.cnxset
   945             self._tx.cnxset = None
   946             self._tx.ctx_count -= 1
   946             self._tx.ctx_count -= 1
   947 
   947 
   948     def _touch(self):
   948     def _touch(self):
   949         """update latest session usage timestamp and reset mode to read"""
   949         """update latest session usage timestamp and reset mode to read"""
   950         self.timestamp = time()
   950         self.timestamp = time()
  1147         if reset_pool is not None:
  1147         if reset_pool is not None:
  1148             warn('[3.13] use free_cnxset argument instead for reset_pool',
  1148             warn('[3.13] use free_cnxset argument instead for reset_pool',
  1149                  DeprecationWarning, stacklevel=2)
  1149                  DeprecationWarning, stacklevel=2)
  1150             free_cnxset = reset_pool
  1150             free_cnxset = reset_pool
  1151         # don't use self.cnxset, rollback may be called with _closed == True
  1151         # don't use self.cnxset, rollback may be called with _closed == True
  1152         cnxset = getattr(self._tx, 'cnxset', None)
  1152         cnxset = self._tx.cnxset
  1153         if cnxset is None:
  1153         if cnxset is None:
  1154             self._clear_thread_data()
  1154             self._clear_thread_data()
  1155             self._touch()
  1155             self._touch()
  1156             self.debug('rollback session %s done (no db activity)', self.id)
  1156             self.debug('rollback session %s done (no db activity)', self.id)
  1157             return
  1157             return
  1284     def cnxset(self):
  1284     def cnxset(self):
  1285         """connections set, set according to transaction mode for each query"""
  1285         """connections set, set according to transaction mode for each query"""
  1286         if self.repo.shutting_down:
  1286         if self.repo.shutting_down:
  1287             self.free_cnxset(True)
  1287             self.free_cnxset(True)
  1288             raise ShuttingDown('repository is shutting down')
  1288             raise ShuttingDown('repository is shutting down')
  1289         return getattr(self._tx, 'cnxset', None)
  1289         return self._tx.cnxset
  1290 
  1290 
  1291 
  1291 
  1292 class InternalManager(object):
  1292 class InternalManager(object):
  1293     """a manager user with all access rights used internally for task such as
  1293     """a manager user with all access rights used internally for task such as
  1294     bootstrapping the repository or creating regular users according to
  1294     bootstrapping the repository or creating regular users according to