Skip to content

Add Pool.is_closing() method #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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