]> 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>
Fri, 13 Oct 2023 23:10:12 +0000 (01:10 +0200)
psycopg_pool/psycopg_pool/pool_async.py

index cbafa9c858ac99b48e0ff7faa5fa29692aacfa33..ab8cfa4d44e127614db6add9060446e7e081f0b8 100644 (file)
@@ -363,8 +363,12 @@ class AsyncConnectionPool(Generic[ACT], BasePool):
         In async code, also make sure that the loop is running.
         """
         if True:  # ASYNC
-            # 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
 
         try:
             self._lock