Skip to content

Commit

Permalink
Use anyio in AsyncConnection
Browse files Browse the repository at this point in the history
The lock of AsyncConnection is now an anyio.Lock. The check for windows
Proactor event loop is adjusted accordingly.
  • Loading branch information
dlax committed Nov 17, 2021
1 parent 97aa57a commit 4b80d75
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions psycopg/psycopg/connection_async.py
Expand Up @@ -5,20 +5,22 @@
# Copyright (C) 2020-2021 The Psycopg Team

import sys
import asyncio
import logging
from types import TracebackType
from typing import Any, AsyncGenerator, AsyncIterator, Dict, Optional
from typing import Type, Union, cast, overload, TYPE_CHECKING

import anyio
import sniffio

from . import errors as e
from . import waiting
from .pq import Format
from .abc import AdaptContext, Params, PQGen, PQGenConn, Query, RV
from .rows import Row, AsyncRowFactory, tuple_row, TupleRow
from .adapt import AdaptersMap
from ._enums import IsolationLevel
from ._compat import asynccontextmanager, get_running_loop
from ._compat import asynccontextmanager
from .conninfo import make_conninfo, conninfo_to_dict
from ._encodings import pgconn_encoding
from .connection import BaseConnection, CursorRow, Notify
Expand Down Expand Up @@ -52,7 +54,7 @@ def __init__(
):
super().__init__(pgconn)
self.row_factory = row_factory or cast(AsyncRowFactory[Row], tuple_row)
self.lock = asyncio.Lock()
self.lock = anyio.Lock()
self.cursor_factory = AsyncCursor
self.server_cursor_factory = AsyncServerCursor

Expand Down Expand Up @@ -92,7 +94,13 @@ async def connect(
**kwargs: Any,
) -> "AsyncConnection[Any]":

if sys.platform == "win32":
if (
sys.platform == "win32"
and sniffio.current_async_library() == "asyncio"
):
import asyncio
from ._compat import get_running_loop

loop = get_running_loop()
if isinstance(loop, asyncio.ProactorEventLoop):
raise e.InterfaceError(
Expand Down

0 comments on commit 4b80d75

Please sign in to comment.