]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
style(pool): more explicit error message for pool open with no loop
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 8 Oct 2023 17:31:07 +0000 (19:31 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 8 Oct 2023 18:50:57 +0000 (20:50 +0200)
psycopg_pool/psycopg_pool/pool_async.py

index fa310b129b5c411e4c737591b7db2bc51ec81f65..e08f0c49484f2e9e4562b27ad079a0f51731bc60 100644 (file)
@@ -232,8 +232,12 @@ class AsyncConnectionPool(BasePool[AsyncConnection[Any]]):
         if not self._closed:
             return
 
-        # Throw a RuntimeError if the pool is open outside a running loop.
-        asyncio.get_running_loop()
+        try:
+            asyncio.get_running_loop()
+        except RuntimeError:
+            raise RuntimeError(
+                f"{type(self).__name__} open with no running loop"
+            ) from None
 
         self._check_open()