equal
deleted
inserted
replaced
386 self._txs = {} |
386 self._txs = {} |
387 # Data local to the thread |
387 # Data local to the thread |
388 self.__threaddata = threading.local() |
388 self.__threaddata = threading.local() |
389 self._threads_in_transaction = set() |
389 self._threads_in_transaction = set() |
390 self._closed = False |
390 self._closed = False |
391 self._closed_lock = threading.Lock() |
391 self._lock = threading.RLock() |
392 |
392 |
393 def __unicode__(self): |
393 def __unicode__(self): |
394 return '<session %s (%s 0x%x)>' % ( |
394 return '<session %s (%s 0x%x)>' % ( |
395 unicode(self.user.login), self.id, id(self)) |
395 unicode(self.user.login), self.id, id(self)) |
396 |
396 |
859 raise Exception('try to access connections set on a closed session %s' % self.id) |
859 raise Exception('try to access connections set on a closed session %s' % self.id) |
860 return getattr(self._tx, 'cnxset', None) |
860 return getattr(self._tx, 'cnxset', None) |
861 |
861 |
862 def set_cnxset(self): |
862 def set_cnxset(self): |
863 """the session need a connections set to execute some queries""" |
863 """the session need a connections set to execute some queries""" |
864 with self._closed_lock: |
864 with self._lock: |
865 if self._closed: |
865 if self._closed: |
866 self.free_cnxset(True) |
866 self.free_cnxset(True) |
867 raise Exception('try to set connections set on a closed session %s' % self.id) |
867 raise Exception('try to set connections set on a closed session %s' % self.id) |
868 if self.cnxset is None: |
868 if self.cnxset is None: |
869 # get connections set first to avoid race-condition |
869 # get connections set first to avoid race-condition |
1151 self.free_cnxset(ignoremode=True) |
1151 self.free_cnxset(ignoremode=True) |
1152 self._clear_thread_data(free_cnxset) |
1152 self._clear_thread_data(free_cnxset) |
1153 |
1153 |
1154 def close(self): |
1154 def close(self): |
1155 """do not close connections set on session close, since they are shared now""" |
1155 """do not close connections set on session close, since they are shared now""" |
1156 with self._closed_lock: |
1156 with self._lock: |
1157 self._closed = True |
1157 self._closed = True |
1158 # copy since _threads_in_transaction maybe modified while waiting |
1158 # copy since _threads_in_transaction maybe modified while waiting |
1159 for thread, cnxset in self._threads_in_transaction.copy(): |
1159 for thread, cnxset in self._threads_in_transaction.copy(): |
1160 if thread is threading.currentThread(): |
1160 if thread is threading.currentThread(): |
1161 continue |
1161 continue |