From 30b9ea5261ed398107631497dcc76aa6e1fd79b7 Mon Sep 17 00:00:00 2001 From: Richard Schwab Date: Wed, 2 Feb 2022 23:35:28 +0100 Subject: [PATCH] add Pool.closed property as present in aiopg, fixes #463 (#726) --- CHANGES.txt | 1 + aiomysql/pool.py | 9 ++++++++- tests/test_pool.py | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8d76df9a..83f7ec11 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -18,6 +18,7 @@ To be included in 1.0.0 (unreleased) * Bump minimal PyMySQL version to 1.0.0 #713 * Align % formatting in Cursor.executemany() with Cursor.execute(), literal % now need to be doubled in Cursor.executemany() #714 * Fixed unlimited Pool size not working, this is now working as documented by passing maxsize=0 to create_pool #119 +* Added Pool.closed property as present in aiopg #463 0.0.22 (2021-11-14) diff --git a/aiomysql/pool.py b/aiomysql/pool.py index 47f14bb5..dc1cbf93 100644 --- a/aiomysql/pool.py +++ b/aiomysql/pool.py @@ -1,4 +1,4 @@ -# copied from aiopg +# based on aiopg pool # https://github.com/aio-libs/aiopg/blob/master/aiopg/pool.py import asyncio @@ -79,6 +79,13 @@ async def clear(self): await conn.ensure_closed() self._cond.notify() + @property + def closed(self): + """ + The readonly property that returns ``True`` if connections is closed. + """ + return self._closed + def close(self): """Close pool. diff --git a/tests/test_pool.py b/tests/test_pool.py index c87d0849..0921e936 100644 --- a/tests/test_pool.py +++ b/tests/test_pool.py @@ -345,6 +345,7 @@ async def wait_closed(): await asyncio.gather(wait_closed(), do_release(c1), do_release(c2)) assert ['release', 'release', 'wait_closed'] == ops assert 0 == pool.freesize + assert pool.closed @pytest.mark.run_loop