From: Daniele Varrazzo Date: Sun, 18 Feb 2024 00:03:20 +0000 (+0100) Subject: docs(pool): add box warning against opening async pools on init X-Git-Tag: pool-3.2.2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5dd8e9d11eff54abd6924730e46ac03553d4873;p=thirdparty%2Fpsycopg.git docs(pool): add box warning against opening async pools on init --- diff --git a/docs/advanced/pool.rst b/docs/advanced/pool.rst index 2d75edfb3..5badde817 100644 --- a/docs/advanced/pool.rst +++ b/docs/advanced/pool.rst @@ -304,15 +304,15 @@ call the `~ConnectionPool.open()` method (and optionally the `~ClonnectionPool.close()` method) at application startup/shutdown. For example, in FastAPI, you can use `startup/shutdown events`__:: - pool = ConnectionPool(..., open=False, ...) + pool = AsyncConnectionPool(..., open=False, ...) @app.on_event("startup") - def open_pool(): - pool.open() + async def open_pool(): + await pool.open() @app.on_event("shutdown") - def close_pool(): - pool.close() + async def close_pool(): + await pool.close() .. __: https://fastapi.tiangolo.com/advanced/events/#events-startup-shutdown @@ -322,6 +322,11 @@ example, in FastAPI, you can use `startup/shutdown events`__:: be changed to `!False`. As a consequence, if you rely on the pool to be opened on creation, you should specify `!open=True` explicitly. +.. warning:: + Opening an async pool in the constructor is deprecated and will be removed + in the future. When using `AsyncConnectionPool` you should call `await + pool.open()` or `async with ... as pool` explicitly. + .. _null-pool: