Skip to content

Commit

Permalink
(jkklee#19) feat: singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
seunggabi committed Aug 16, 2023
1 parent cfa69f8 commit 38fa566
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ eggs
.idea
test.py
*.swp

venv
14 changes: 14 additions & 0 deletions pymysqlpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,17 @@ def wrapper(*args, **kwargs):
for name, fn in inspect.getmembers(Connection, inspect.isfunction):
if not name.startswith('_'):
setattr(Connection, name, already_returned_conn(fn))


class ConnectionPoolSingleton:
_instance = None

def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = cls._create_pool(*args, **kwargs)

return cls._instance

@staticmethod
def _create_pool(*args, **kwargs):
return ConnectionPool(*args, **kwargs)

0 comments on commit 38fa566

Please sign in to comment.