From: Daniele Varrazzo Date: Sun, 21 Feb 2021 03:48:03 +0000 (+0100) Subject: pool.close() called on del, idemptotent X-Git-Tag: 3.0.dev0~87^2~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e53dd8cb1b1b2c9438133eade53710281589b9fe;p=thirdparty%2Fpsycopg.git pool.close() called on del, idemptotent --- diff --git a/psycopg3/psycopg3/pool.py b/psycopg3/psycopg3/pool.py index 8c62faaa3..6b8aa28cf 100644 --- a/psycopg3/psycopg3/pool.py +++ b/psycopg3/psycopg3/pool.py @@ -123,6 +123,9 @@ class ConnectionPool: f" {self.name!r} at 0x{id(self):x}>" ) + def __del__(self) -> None: + self.close() + @contextmanager def connection( self, timeout: Optional[float] = None @@ -312,6 +315,9 @@ class ConnectionPool: with a `PoolClosed` exception. Currently used connections will not be closed until returned to the pool. """ + if self._closed: + return + with self._lock: self._closed = True