From: Daniele Varrazzo Date: Sun, 8 Oct 2023 17:31:07 +0000 (+0200) Subject: style(pool): more explicit error message for pool open with no loop X-Git-Tag: pool-3.2.0~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8619bc41569fcb85ac3fa08fe5c529d075aea4bd;p=thirdparty%2Fpsycopg.git style(pool): more explicit error message for pool open with no loop --- diff --git a/psycopg_pool/psycopg_pool/pool_async.py b/psycopg_pool/psycopg_pool/pool_async.py index cbafa9c85..ab8cfa4d4 100644 --- a/psycopg_pool/psycopg_pool/pool_async.py +++ b/psycopg_pool/psycopg_pool/pool_async.py @@ -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