# Copyright (C) 2020-2021 The Psycopg Team
+import sys
import asyncio
import logging
-import sys
from types import TracebackType
from typing import Any, AsyncIterator, Dict, Optional, Type, Union
from typing import cast, overload, TYPE_CHECKING
from .rows import Row, AsyncRowFactory, tuple_row, TupleRow
from .adapt import AdaptersMap
from ._enums import IsolationLevel
-from ._compat import asynccontextmanager
+from ._compat import asynccontextmanager, get_running_loop
from .conninfo import make_conninfo, conninfo_to_dict
from ._encodings import pgconn_encoding
from .connection import BaseConnection, CursorRow, Notify
) -> "AsyncConnection[Any]":
if sys.platform == "win32":
- if sys.version_info < (3, 7):
- loop = asyncio.get_event_loop()
- else:
- loop = asyncio.get_running_loop()
+ loop = get_running_loop()
if isinstance(loop, asyncio.ProactorEventLoop):
raise e.InterfaceError(
- "psycopg does not currently support running in async mode "
- "on windows on the 'ProactorEventLoop'. "
- "Please ensure that a compatible event loop is used, like "
- "by setting ``asyncio.set_event_loop_policy`` to "
- "WindowsSelectorEventLoopPolicy"
+ "Psycopg cannot use the 'ProactorEventLoop' to run in async"
+ " mode. Please use a compatible event loop, for instance by"
+ " setting 'asyncio.set_event_loop_policy"
+ "(WindowsSelectorEventLoopPolicy())'"
)
params = await cls._get_connection_params(conninfo, **kwargs)
assert (await cur.fetchone())[0] == "hellob"
-@pytest.mark.skipif(sys.platform != "win32", reason="windows is required")
+@pytest.mark.skipif(sys.platform != "win32", reason="windows only test")
def test_windows_error(dsn):
loop = asyncio.ProactorEventLoop()
async def go():
with pytest.raises(
InterfaceError,
- match="psycopg does not currently support running in async mode",
+ match="Psycopg cannot use the 'ProactorEventLoop'",
):
await psycopg.AsyncConnection.connect(dsn)