def do_get(self): try: return self._conns[thread.get_ident()] except KeyError: c = self.create_connection() self._conns[thread.get_ident()] = c if len(self._conns) > self.size: self.cleanup() return c
def connect(self): if not self._use_threadlocal: return _ConnectionFairy(self).checkout() try: return self._threadconns[thread.get_ident()].checkout() except KeyError: agent = _ConnectionFairy(self) self._threadconns[thread.get_ident()] = agent return agent.checkout()
def status(self): return "SingletonThreadPool id:%d thread:%d size: %d" % ( id(self), thread.get_ident(), len(self._conns))
def dispose_local(self): try: del self._conns[thread.get_ident()] except KeyError: pass
def return_conn(self, record): if self._use_threadlocal and thread.get_ident() in self._threadconns: del self._threadconns[thread.get_ident()] self.do_return_conn(record)
def status(self): return "SingletonThreadPool id:%d thread:%d size: %d" % (id(self), thread.get_ident(), len(self._conns))