From 0a320dd1d90845c9df28be5b59a00c6c734b7264 Mon Sep 17 00:00:00 2001 From: Paul Weaver Date: Wed, 21 May 2025 15:40:53 +0100 Subject: [PATCH 1/4] Catch explicit Exception So that it `c.ping()` hangs forever, the interrupt from a users Ctrl+C will still cause the process to terminate. --- pymysqlpool/pool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymysqlpool/pool.py b/pymysqlpool/pool.py index b511de9..050dc24 100644 --- a/pymysqlpool/pool.py +++ b/pymysqlpool/pool.py @@ -182,7 +182,7 @@ def __get_safe_conn(self, retry_count): if c.__ping_check_timestamp < timeout: c.__ping_check_timestamp = now c.ping() - except: + except Exception: self.current_size -= 1 if retry_count < 10: c = self.__get_conn(retry_count+1) if c: self.inuse_list.add(c) From 7b0e16232193065c18f1d77d1d1f08cb24d63e43 Mon Sep 17 00:00:00 2001 From: Paul Weaver Date: Wed, 21 May 2025 15:42:01 +0100 Subject: [PATCH 2/4] Fix type annotation --- pymysqlpool/pool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymysqlpool/pool.py b/pymysqlpool/pool.py index 050dc24..f8fb0c6 100644 --- a/pymysqlpool/pool.py +++ b/pymysqlpool/pool.py @@ -78,7 +78,7 @@ def __init__(self, multiple=4, counter=0, accumulation=0, - ping_check: (int, bool) = False, + ping_check: int | bool = False, **configs): self.host = host self.port = port From 0a24efefbb92237e8080e55d4342ae8cbdbfec14 Mon Sep 17 00:00:00 2001 From: Paul Weaver Date: Wed, 21 May 2025 15:42:21 +0100 Subject: [PATCH 3/4] Annotate password type and adapt for PyMySql cursor interface This was giving a type error in my IDE. --- pymysqlpool/pool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymysqlpool/pool.py b/pymysqlpool/pool.py index f8fb0c6..bdc2c6e 100644 --- a/pymysqlpool/pool.py +++ b/pymysqlpool/pool.py @@ -64,7 +64,7 @@ def __init__(self, host="localhost", port=3306, user=None, - password=None, + password: str | None = None, unix_socket=None, db=None, charset="utf8", @@ -115,7 +115,7 @@ def create_conn(self): host=self.host, port=self.port, user=self.user, - password=self.password, + password=self.password or "", db=self.db, charset=self.charset, cursorclass=self.cursorclass, From 8f2d7cad9f78b6a60c82eda63f6187365cb099a3 Mon Sep 17 00:00:00 2001 From: Paul Weaver Date: Wed, 21 May 2025 15:43:08 +0100 Subject: [PATCH 4/4] Formatting This was giving some easy-to-fix errors in my IDE. --- pymysqlpool/pool.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pymysqlpool/pool.py b/pymysqlpool/pool.py index bdc2c6e..fab4a1e 100644 --- a/pymysqlpool/pool.py +++ b/pymysqlpool/pool.py @@ -184,8 +184,10 @@ def __get_safe_conn(self, retry_count): c.ping() except Exception: self.current_size -= 1 - if retry_count < 10: c = self.__get_conn(retry_count+1) - if c: self.inuse_list.add(c) + if retry_count < 10: + c = self.__get_conn(retry_count+1) + if c: + self.inuse_list.add(c) return c def get_pool_size(self):