This makes it symmetrical with close(). However it doesn't really do any
async work as it's awkward to call it from init. Something we might do,
if that will be needed, could be to start the scheduler only and use it
to schedule immediately a call to an async _open().
In the future, an anyio-based pool might instead disallow open=True on
init.
See https://github.com/psycopg/psycopg/pull/151 for some discussion
about the topic.
super().__init__(conninfo, **kwargs)
if open:
- self.open()
+ self._open()
async def wait(self, timeout: float = 30.0) -> None:
async with self._lock:
else:
await self._return_connection(conn)
- def open(self) -> None:
+ async def open(self) -> None:
+ async with self._lock:
+ self._open()
+
+ def _open(self) -> None:
if not self._closed:
return
)
async def __aenter__(self) -> "AsyncConnectionPool":
- self.open()
+ await self.open()
return self
async def __aexit__(
async with p.connection():
pass
- p.open()
+ await p.open()
try:
assert not p.closed
p = pool.AsyncConnectionPool(dsn)
try:
assert not p.closed
- p.open()
+ await p.open()
assert not p.closed
async with p.connection() as conn:
assert p._sched_runner is None
with pytest.raises(OperationalError, match="cannot be reused"):
- p.open()
+ await p.open()
@pytest.mark.slow