pymysql-pool icon indicating copy to clipboard operation
pymysql-pool copied to clipboard

a little problem with pool size but it doesn't matter

Open mysqldba-nandy opened this issue 5 years ago • 5 comments

  • NEW
class ConnectionPool:
    _HARD_LIMIT = 100
    _THREAD_LOCAL = threading.local()
    _THREAD_LOCAL.retry_counter = 0  # a counter used for debug get_connection() method

    def __init__(self, size=5, name=None, *args, **kwargs):
    *   self.size =  size < self._HARD_LIMIT and size or self._HARD_LIMIT
    *   self._pool = queue.Queue(self.size)
        self.name = name if name else '-'.join(
            [kwargs.get('host', 'localhost'), str(kwargs.get('port', 3306)),
             kwargs.get('user', ''), kwargs.get('database', '')])
    *   for _ in range(self.size):
            conn = Connection(*args, **kwargs)
            conn._pool = self
            self._pool.put(conn)

    def put_connection(self, conn):
        if not conn._pool:
            conn._pool = self
        conn.cursor().close()
        try:
            self._pool.put_nowait(conn)
            logger.debug("Put connection back to pool(%s)", self.name)
        except queue.Full:
    *       logger.warning("Put connection to pool(%s) error, pool is full, size:%d", self.name, self.size))

    # def size(self):
    #    return self._pool.qsize()

mysqldba-nandy avatar Mar 06 '19 04:03 mysqldba-nandy

Do you mean the value of size isn't strict enough?

jkklee avatar Mar 06 '19 07:03 jkklee

function "size" uses the same name with parameter "size" ,which may lead to errors

wangzihuacool avatar Aug 17 '19 03:08 wangzihuacool

I had the same prob, so I put my solution here: https://github.com/jkklee/pymysql-pool/pull/6

damiannmm avatar Sep 30 '19 07:09 damiannmm

if the connection pool is full there is an error when requesting a connection ` line 143, in put_connection logger.warning("Put connection to pool(%s) error, pool is full, size:%d", self.name, self.size())

TypeError: 'int' object is not callable`

lotusorrose avatar Jan 01 '20 20:01 lotusorrose

@20bt13github I have publish the version 0.3.4 in the PYPI, you can upgrade this package using pip install --upgrade pymysql-pool to solve your problem.

jkklee avatar Jan 05 '20 15:01 jkklee