From: Denis Laxalde Date: Tue, 16 Apr 2024 07:11:30 +0000 (+0200) Subject: refactor: set the meaningful timeout for _try_cancel() as a default X-Git-Tag: 3.2.0~41^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F780%2Fhead;p=thirdparty%2Fpsycopg.git refactor: set the meaningful timeout for _try_cancel() as a default --- diff --git a/psycopg/psycopg/_copy.py b/psycopg/psycopg/_copy.py index d4db84a2d..2b0e77ca7 100644 --- a/psycopg/psycopg/_copy.py +++ b/psycopg/psycopg/_copy.py @@ -160,7 +160,7 @@ class Copy(BaseCopy["Connection[Any]"]): # (which might or might not have been already transferred entirely to # the client, so we won't necessary see the exception associated with # canceling). - self.connection._try_cancel(timeout=5.0) + self.connection._try_cancel() self.connection.wait(self._end_copy_out_gen()) diff --git a/psycopg/psycopg/_copy_async.py b/psycopg/psycopg/_copy_async.py index a371f185d..c94f05db9 100644 --- a/psycopg/psycopg/_copy_async.py +++ b/psycopg/psycopg/_copy_async.py @@ -159,7 +159,7 @@ class AsyncCopy(BaseCopy["AsyncConnection[Any]"]): # (which might or might not have been already transferred entirely to # the client, so we won't necessary see the exception associated with # canceling). - await self.connection._try_cancel(timeout=5.0) + await self.connection._try_cancel() await self.connection.wait(self._end_copy_out_gen()) diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index ad233c375..c2be01560 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -288,7 +288,7 @@ class Connection(BaseConnection[Row]): else: self.cancel() - def _try_cancel(self, *, timeout: float = 30.0) -> None: + def _try_cancel(self, *, timeout: float = 5.0) -> None: try: self.cancel_safe(timeout=timeout) except Exception as ex: diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index 785018522..b0c8b753e 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -308,7 +308,7 @@ class AsyncConnection(BaseConnection[Row]): else: self.cancel() - async def _try_cancel(self, *, timeout: float = 30.0) -> None: + async def _try_cancel(self, *, timeout: float = 5.0) -> None: try: await self.cancel_safe(timeout=timeout) except Exception as ex: diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index b49c3e5af..42d5d8e45 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -159,7 +159,7 @@ class Cursor(BaseCursor["Connection[Any]", Row]): if self._pgconn.transaction_status == ACTIVE: # Try to cancel the query, then consume the results # already received. - self._conn._try_cancel(timeout=5.0) + self._conn._try_cancel() try: while self._conn.wait(self._stream_fetchone_gen(first=False)): pass diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index 46700da52..37a0d255f 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -164,7 +164,7 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): if self._pgconn.transaction_status == ACTIVE: # Try to cancel the query, then consume the results # already received. - await self._conn._try_cancel(timeout=5.0) + await self._conn._try_cancel() try: while await self._conn.wait( self._stream_fetchone_gen(first=False)