aio-libs / aiopg

aiopg is a library for accessing a PostgreSQL database from the asyncio
http://aiopg.readthedocs.io
BSD 2-Clause "Simplified" License
1.4k stars 160 forks source link

Can't create pool on MacOS #912

Open sxkxixx opened 2 weeks ago

sxkxixx commented 2 weeks ago

Describe the bug

Using version aiopg="1.4.0", I can not execute example code from README.md.

import asyncio
import aiopg

dsn = 'dbname=... user=... password=... host=... port=...'

async def go():
    async with aiopg.create_pool(dsn) as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute("SELECT 1")
                ret = []
                async for row in cur:
                    ret.append(row)
                assert ret == [(1,)]

loop = asyncio.get_event_loop()
loop.run_until_complete(go())

To Reproduce

  1. Copy example code from README.md
  2. Run postgresql in Docker container
  3. Run example code

Expected behavior

Pool successfully creates and sql query executes

Logs/tracebacks

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/.../PycharmProjects/sandbox/main.py", line 20, in <module>
    loop.run_until_complete(go())
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/.../PycharmProjects/sandbox/main.py", line 9, in go
    async with aiopg.create_pool(dsn) as pool:
  File "/Users/.../Library/Caches/pypoetry/virtualenvs/sandbox-N2CgpaeM-py3.11/lib/python3.11/site-packages/aiopg/utils.py", line 82, in __aenter__
    self._obj = await self._coro
                ^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/pypoetry/virtualenvs/sandbox-N2CgpaeM-py3.11/lib/python3.11/site-packages/aiopg/pool.py", line 300, in from_pool_fill
    await self._fill_free_pool(False)
  File "/Users/.../Library/Caches/pypoetry/virtualenvs/sandbox-N2CgpaeM-py3.11/lib/python3.11/site-packages/aiopg/pool.py", line 336, in _fill_free_pool
    conn = await connect(
           ^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/pypoetry/virtualenvs/sandbox-N2CgpaeM-py3.11/lib/python3.11/site-packages/aiopg/connection.py", line 1225, in _connect
    await self._poll(self._waiter, self._timeout)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Library/Caches/pypoetry/virtualenvs/sandbox-N2CgpaeM-py3.11/lib/python3.11/site-packages/aiopg/connection.py", line 884, in _poll
    raise exc
  File "/Users/.../Library/Caches/pypoetry/virtualenvs/sandbox-N2CgpaeM-py3.11/lib/python3.11/site-packages/aiopg/connection.py", line 881, in _poll
    await asyncio.wait_for(self._waiter, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

Python Version

$ python --version
Python 3.11.4

aiopg Version

$ python -m pip show aiopg
1.4.0

OS

MacOS Apple M3 Pro Sonoma 14.6.1

Additional context

Code of Conduct