Skip to content

Commit

Permalink
remove warnings from the pool.py module; move AsynchPoolError into th…
Browse files Browse the repository at this point in the history
…e errors.py module
  • Loading branch information
Stanley Kudrow committed Oct 18, 2024
1 parent c4f9330 commit f4ff439
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
2 changes: 1 addition & 1 deletion asynch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from asynch.connection import Connection, connect # noqa: F401
from asynch.cursors import Cursor, DictCursor # noqa: F401
from asynch.pool import Pool, create_async_pool # noqa: F401
from asynch.pool import Pool, create_pool # noqa: F401
4 changes: 4 additions & 0 deletions asynch/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,7 @@ class NotSupportedError(DatabaseError):
It must be a subclass of DatabaseError.
"""


class AsynchPoolError(ClickHouseException):
pass
24 changes: 2 additions & 22 deletions asynch/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
from collections import deque
from contextlib import asynccontextmanager
from typing import AsyncIterator, Optional
from warnings import warn

from asynch.connection import Connection, connect
from asynch.errors import ClickHouseException
from asynch.errors import AsynchPoolError
from asynch.proto import constants
from asynch.proto.models.enums import PoolStatus

logger = logging.getLogger(__name__)


class AsynchPoolError(ClickHouseException):
pass


class Pool(asyncio.AbstractServer):
def __init__(
self,
minsize: int = constants.POOL_MIN_SIZE,
maxsize: int = constants.POOL_MAX_SIZE,
loop: Optional[asyncio.AbstractEventLoop] = None,
**kwargs,
):
if maxsize < 1:
Expand All @@ -34,25 +28,11 @@ def __init__(
self._maxsize = maxsize
self._minsize = minsize
self._connection_kwargs = kwargs
self._terminated: set[Connection] = set()
self._used: set[Connection] = set()
self._cond = asyncio.Condition()
self._closing = False
self._lock = asyncio.Lock()
self._acquired_connections: deque[Connection] = deque(maxlen=maxsize)
self._free_connections: deque[Connection] = deque(maxlen=maxsize)
self._opened: Optional[bool] = None
self._closed: Optional[bool] = None
warn(
(
"The loop parameter must be removed when Python3.10 "
"will be the minimum version (in a year) or earlier."
),
DeprecationWarning,
)
self._loop = (
loop if isinstance(loop, asyncio.AbstractEventLoop) else asyncio.get_running_loop()
)

async def __aenter__(self) -> "Pool":
await self.startup()
Expand Down Expand Up @@ -243,7 +223,7 @@ async def shutdown(self) -> None:
self._closed = True


async def create_async_pool(
async def create_pool(
minsize: int = constants.POOL_MIN_SIZE,
maxsize: int = constants.POOL_MAX_SIZE,
loop: Optional[asyncio.AbstractEventLoop] = None,
Expand Down

0 comments on commit f4ff439

Please sign in to comment.