Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions asyncpg/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ async def _initialize(self):

await asyncio.gather(*connect_tasks)

@property
def closed(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it a method called is_closing() and take into account the _closing property too. This would make Pool consistent with the asyncio transport API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

"""Return a boolean for whether this pool has already been closed/terminated.

.. versionadded:: 0.28.0
"""
return self._closed

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_closed(self):
async with self.create_pool() as pool:
self.assertFalse(pool.closed)
await pool.close()
self.assertTrue(pool.closed)

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

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