From 12ffe9e1ea677ecef05be17cbe67db0cf057108f Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 13 Nov 2024 14:31:32 +0100 Subject: [PATCH] docs(pool): suggest closing the pool explicitly On Python 3.13 threads may fail to stop. See #930, #954. --- docs/advanced/pool.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/advanced/pool.rst b/docs/advanced/pool.rst index 46fc308e7..6b41a7c05 100644 --- a/docs/advanced/pool.rst +++ b/docs/advanced/pool.rst @@ -158,9 +158,17 @@ global object and use it from the rest of your code:: Using this pattern, the pool will start the connection process already at import time. If that's too early, and you want to delay opening connections until the application is ready, you can specify to create a closed pool and -call the `~ConnectionPool.open()` method (and optionally the -`~ClonnectionPool.close()` method) at application startup/shutdown. For -example, in FastAPI, you can use a `Lifespan`__:: +call the `~ConnectionPool.open()` method. + +If you are not using the pool as context manager, you are advised to call the +`~ConnectionPool.close()` method on program exit: on some Python versions this +might cause a program exit delay. How to ensure it depends on the way you are +writing your program. One simple method is to use the `atexit` module:: + + atexit.register(pool.close) + +Other frameworks might provide suitable hooks. For example, in FastAPI, you +can use a `lifespan`__ function:: pool = AsyncConnectionPool(..., open=False, ...) -- 2.47.2