pymysql-pool
pymysql-pool copied to clipboard
a little problem with pool size but it doesn't matter
- 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()
Do you mean the value of size
isn't strict enough?
function "size" uses the same name with parameter "size" ,which may lead to errors
I had the same prob, so I put my solution here: https://github.com/jkklee/pymysql-pool/pull/6
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`
@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.