MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / release

Method release

asyncpg/pool.py:1019–1055  ·  view source on GitHub ↗

Release a database connection back to the pool. :param Connection connection: A :class:`~asyncpg.connection.Connection` object to release. :param float timeout: A timeout for releasing the connection. If not specified, defaults to the timeout pro

(self, connection, *, timeout=None)

Source from the content-addressed store, hash-verified

1017 _acquire_impl(), timeout=timeout)
1018
1019 async def release(self, connection, *, timeout=None):
1020 """Release a database connection back to the pool.
1021
1022 :param Connection connection:
1023 A :class:`~asyncpg.connection.Connection` object to release.
1024 :param float timeout:
1025 A timeout for releasing the connection. If not specified, defaults
1026 to the timeout provided in the corresponding call to the
1027 :meth:`Pool.acquire() <asyncpg.pool.Pool.acquire>` method.
1028
1029 .. versionchanged:: 0.14.0
1030 Added the *timeout* parameter.
1031 """
1032 if (type(connection) is not PoolConnectionProxy or
1033 connection._holder._pool is not self):
1034 raise exceptions.InterfaceError(
1035 'Pool.release() received invalid connection: '
1036 '{connection!r} is not a member of this pool'.format(
1037 connection=connection))
1038
1039 if connection._con is None:
1040 # Already released, do nothing.
1041 return
1042
1043 self._check_init()
1044
1045 # Let the connection do its internal housekeeping when its released.
1046 connection._con._on_release()
1047
1048 ch = connection._holder
1049 if timeout is None:
1050 timeout = ch._timeout
1051
1052 # Use asyncio.shield() to guarantee that task cancellation
1053 # does not prevent the connection from being returned to the
1054 # pool properly.
1055 return await asyncio.shield(ch.release(timeout))
1056
1057 async def close(self):
1058 """Attempt to gracefully close all connections in the pool.

Calls 2

_check_initMethod · 0.95
_on_releaseMethod · 0.80