Skip to content

Commit

Permalink
misc: little change for improve the e43a599
Browse files Browse the repository at this point in the history
  • Loading branch information
jk.li02 committed Mar 8, 2022
1 parent e43a599 commit 622c808
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pymysqlpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class ConnectionPool:
put a reusable connection back to the pool, etc; also we can create different instance of this class that represent
different pool of different DB Server or different user
"""
_created_num = deque() # record the number of all used and available connections(use deque for thread-safe)

def __init__(self, size=10, maxsize=100, name=None, pre_create_num=0, con_lifetime=3600, *args, **kwargs):
"""
Expand Down Expand Up @@ -152,6 +151,7 @@ def __init__(self, size=10, maxsize=100, name=None, pre_create_num=0, con_lifeti
self.name = name if name else '-'.join(
[kwargs.get('host', 'localhost'), str(kwargs.get('port', 3306)),
kwargs.get('user', ''), kwargs.get('database', '')])
self._created_num = deque() # record the number of all used and available connections(use deque for thread-safe)

if pre_create_num > 0:
for _ in range(self._pre_create_num):
Expand Down Expand Up @@ -187,7 +187,7 @@ def get_connection(self, retry_num=3, retry_interval=0.1, pre_ping=False):
if self.connection_num < self.maxsize:
return self._create_connection()
else:
raise GetConnectionFromPoolError("can't get connection from pool({}), retry_num={} retry_interval={}(s)".format(
raise GetConnectionFromPoolError("can't get connection from pool({}), retry_interval={}(s)".format(
self.name, retry_num, retry_interval))

# check con_lifetime
Expand Down

0 comments on commit 622c808

Please sign in to comment.