Skip to content

Commit

Permalink
Add Pool.is_closing() method (MagicStack#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
singingwolfboy committed Dec 3, 2022
1 parent d2e710f commit 9cb2c1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions asyncpg/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ async def _initialize(self):

await asyncio.gather(*connect_tasks)

def is_closing(self):
"""Return ``True`` if the pool is closing or is closed.
.. versionadded:: 0.28.0
"""
return self._closed or self._closing

def get_size(self):
"""Return the current number of connections in this pool.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,17 @@ async def test_pool_size_and_capacity(self):
self.assertEqual(pool.get_size(), 3)
self.assertEqual(pool.get_idle_size(), 0)

async def test_pool_closing(self):
async with self.create_pool() as pool:
self.assertFalse(pool.is_closing())
await pool.close()
self.assertTrue(pool.is_closing())

async with self.create_pool() as pool:
self.assertFalse(pool.is_closing())
pool.terminate()
self.assertTrue(pool.is_closing())

async def test_pool_handles_transaction_exit_in_asyncgen_1(self):
pool = await self.create_pool(database='postgres',
min_size=1, max_size=1)
Expand Down

0 comments on commit 9cb2c1c

Please sign in to comment.