diff --git a/docs/changelog.rst b/docs/changelog.rst index f8cd444..1d0ddf2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,7 +9,7 @@ Changelog 0.11.0 (2024-04-12) ------------------- -- Switch to the ``whenever`` package for date/time types, instead of Arrow. See +- Switch to the ``whenever`` package for date/time types, instead of Arrow. See https://dev.arie.bovenberg.net/blog/python-datetime-pitfalls/ for more information as to why. - ``pg-purepy`` now passes Pyright strict mode. - :class:`.Converter` is now a generic type. diff --git a/docs/conversion.rst b/docs/conversion.rst index c942f9c..80b0233 100644 --- a/docs/conversion.rst +++ b/docs/conversion.rst @@ -35,7 +35,7 @@ Date/Time types .. note:: - I use Whenever over the vanilla ``datetime`` objects because I don't like ``datetime``. Write + I use Whenever over the vanilla ``datetime`` objects because I don't like ``datetime``. Write your own converter if you disagree with me. Enumeration types diff --git a/src/pg_purepy/connection.py b/src/pg_purepy/connection.py index 8dd44b6..9624dff 100644 --- a/src/pg_purepy/connection.py +++ b/src/pg_purepy/connection.py @@ -6,6 +6,7 @@ import types import warnings +from asyncio import lowlevel from collections.abc import AsyncGenerator, AsyncIterator, Mapping from contextlib import aclosing, asynccontextmanager from os import PathLike, fspath @@ -187,7 +188,7 @@ async def _read_until_ready( """ if self._protocol.ready: - await anyio.sleep(0) + await lowlevel.checkpoint() return while True: @@ -210,7 +211,7 @@ async def _read_until_ready( yield next_event if isinstance(next_event, ReadyForQuery): - await anyio.sleep(0) # checkpoint() + await lowlevel.checkpoint() # checkpoint() return to_send = self._protocol.get_needed_synchronisation() @@ -288,13 +289,11 @@ async def lowlevel_query( if not self._protocol.ready: await self.wait_until_ready() - simple_query = all( - ( - not (params or kwargs), - not isinstance(query, PreparedStatementInfo), - max_rows is None, - ) - ) + simple_query = all(( + not (params or kwargs), + not isinstance(query, PreparedStatementInfo), + max_rows is None, + )) logger.debug("Executing query", query=query) if simple_query: @@ -527,7 +526,7 @@ async def row_count(self) -> int: """ if self._row_count >= 0: - await anyio.sleep(0) # checkpoint + await lowlevel.checkpoint() # checkpoint return self._row_count async for _ in self: