Skip to content

Conversation

@1st1
Copy link
Member

@1st1 1st1 commented Mar 29, 2017

Connection pool now wraps all connections in PooledConnectionProxy objects to raise InterfaceError if they are used after being released back to the pool. We also check if connection passed to pool.release actually belong to the pool and correctly handle multiple calls to pool.release with the same connection object.

PooledConnectionProxy transparently wraps Connection instances, exposing all Connection public API.

isinstance(asyncpg.connection.Connection) is True for Instances of PooledConnectionProxy class.

asyncpg/pool.py Outdated
if not self._in_pool:
raise exceptions.InterfaceError(
f'cannot call Connection.{meth.__name__}(): '
f'connection is no longer in the pool')
Copy link
Member

Choose a reason for hiding this comment

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

'connection has been released back to the pool'

Copy link
Member

Choose a reason for hiding this comment

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

No f-strings in 3.5.

asyncpg/pool.py Outdated

def __repr__(self):
if self._con is None:
return f'<{self.__class__.__name__} [not in pool] {id(self):#x}>'
Copy link
Member

Choose a reason for hiding this comment

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

s/[not in pool]/[released]/

asyncpg/pool.py Outdated
event loop will be used.
:return: An instance of :class:`~asyncpg.pool.Pool`.
.. versionchanged:: 0.9.1
Copy link
Member

Choose a reason for hiding this comment

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

0.10.0

asyncpg/pool.py Outdated
:return: An instance of :class:`~asyncpg.pool.Pool`.
.. versionchanged:: 0.9.1
Pool prohibits use of its connections after they were released.
Copy link
Member

Choose a reason for hiding this comment

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

An InterfaceError will be raised on any attempted operation on a released connection.

Connection pool now wraps all connections in `PooledConnectionProxy` objects to raise `InterfaceError` if they are used after being released back to the pool. We also check if connection passed to `pool.release` actually belong to the pool and correctly handle multiple calls to `pool.release` with the same connection object. `PooledConnectionProxy` transparently wraps Connection instances, exposing all Connection public API. `isinstance(asyncpg.connection.Connection)` is `True` for Instances of `PooledConnectionProxy` class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants