

def _close(self, conn, close_conn=False):
    key = self.conn_key(conn)
    if close_conn:
        self._closed.add(key)
        super(PooledDatabase, self)._close(conn)
    elif (key in self._in_use):
        ts = self._in_use[key]
        del self._in_use[key]
        if (self.stale_timeout and self._is_stale(ts)):
            logger.debug('Closing stale connection %s.', key)
            super(PooledDatabase, self)._close(conn)
        else:
            logger.debug('Returning %s to pool.', key)
            heapq.heappush(self._connections, (ts, conn))

dataset/ETHPy150Open coleifer/peewee/playhouse/pool.py PooledDatabase._close/original