Skip to content

Commit 9cb2c1c

Browse files
Add Pool.is_closing() method (#973)
1 parent d2e710f commit 9cb2c1c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Diff for: asyncpg/pool.py

+7
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ async def _initialize(self):
446446

447447
await asyncio.gather(*connect_tasks)
448448

449+
def is_closing(self):
450+
"""Return ``True`` if the pool is closing or is closed.
451+
452+
.. versionadded:: 0.28.0
453+
"""
454+
return self._closed or self._closing
455+
449456
def get_size(self):
450457
"""Return the current number of connections in this pool.
451458

Diff for: tests/test_pool.py

+11
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,17 @@ async def test_pool_size_and_capacity(self):
740740
self.assertEqual(pool.get_size(), 3)
741741
self.assertEqual(pool.get_idle_size(), 0)
742742

743+
async def test_pool_closing(self):
744+
async with self.create_pool() as pool:
745+
self.assertFalse(pool.is_closing())
746+
await pool.close()
747+
self.assertTrue(pool.is_closing())
748+
749+
async with self.create_pool() as pool:
750+
self.assertFalse(pool.is_closing())
751+
pool.terminate()
752+
self.assertTrue(pool.is_closing())
753+
743754
async def test_pool_handles_transaction_exit_in_asyncgen_1(self):
744755
pool = await self.create_pool(database='postgres',
745756
min_size=1, max_size=1)

0 commit comments

Comments
 (0)