From 806d7c7d15b8295f4a1a1bb030cc797726ddafcd Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 8 Oct 2023 19:31:07 +0200 Subject: [PATCH] style(pool): more explicit error message for pool open with no loop --- psycopg_pool/psycopg_pool/pool_async.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/psycopg_pool/psycopg_pool/pool_async.py b/psycopg_pool/psycopg_pool/pool_async.py index fa310b129..e08f0c494 100644 --- a/psycopg_pool/psycopg_pool/pool_async.py +++ b/psycopg_pool/psycopg_pool/pool_async.py @@ -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() -- 2.47.2