psycopg.git / summary / log / commit / refs
commit d2bbfe4e2b1e36a20e72a18097f35a3db27296e3
Author: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Date: Fri Sep 18 01:43:32 2026 +0000
refactor: use get_running_loop() in the async wait functions
`get_event_loop()` is deprecated when called from a coroutine, and these
functions are only ever awaited.
psycopg/psycopg/waiting.py | 6 +++---
tests/test_concurrency_async.py | 2 +-
tools/pproxy_fix.py | 5 +++--
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py
index 19c66d8b..a9dacba0 100644
--- a/psycopg/psycopg/waiting.py
+++ b/psycopg/psycopg/waiting.py
@@ -16,7 +16,7 @@ import select
import logging
import selectors
from time import monotonic
-from asyncio import Event, TimeoutError, get_event_loop, wait_for
+from asyncio import Event, TimeoutError, get_running_loop, wait_for
from selectors import DefaultSelector
from . import errors as e
@@ -180,7 +180,7 @@ async def wait_async(
# Use an event to block and restart after the fd state changes.
# Not sure this is the best implementation but it's a start.
ev = Event()
- loop = get_event_loop()
+ loop = get_running_loop()
ready: int
s: Wait
@@ -251,7 +251,7 @@ async def wait_conn_async(
# Use an event to block and restart after the fd state changes.
# Not sure this is the best implementation but it's a start.
ev = Event()
- loop = get_event_loop()
+ loop = get_running_loop()
ready: Ready
s: Wait
diff --git a/tests/test_concurrency_async.py b/tests/test_concurrency_async.py
index 9e42b84c..6fa14e54 100644
--- a/tests/test_concurrency_async.py
+++ b/tests/test_concurrency_async.py
@@ -159,7 +159,7 @@ import psycopg
async def main():
ctrl_c = False
- loop = asyncio.get_event_loop()
+ loop = asyncio.get_running_loop()
async with await psycopg.AsyncConnection.connect({dsn!r}) as conn:
loop.add_signal_handler(signal.SIGINT, conn.cancel)
cur = conn.cursor()
diff --git a/tools/pproxy_fix.py b/tools/pproxy_fix.py
index b60ec37e..2c3c212c 100644
--- a/tools/pproxy_fix.py
+++ b/tools/pproxy_fix.py
@@ -12,8 +12,9 @@ from pproxy.server import main as main_ # type: ignore[import-untyped]
def main() -> Any:
- # Before Python 3.14 `get_event_loop()` used to create a new loop.
- # From Python 3.14 it raises a `RuntimeError`.
+ # Before Python 3.14 `get_event_loop()` used to create a new loop. From
+ # Python 3.14 it raises a `RuntimeError`. There is no running loop here, so
+ # `get_running_loop()` would always raise.
try:
asyncio.get_event_loop()
except RuntimeError:
[parent: 2b1484a550e0]