MCPcopy
hub / github.com/MagicStack/asyncpg / release

Method release

asyncpg/pool.py:901–937  ·  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

899 _acquire_impl(), timeout=timeout)
900
901 async def release(self, connection, *, timeout=None):
902 """Release a database connection back to the pool.
903
904 :param Connection connection:
905 A :class:`~asyncpg.connection.Connection` object to release.
906 :param float timeout:
907 A timeout for releasing the connection. If not specified, defaults
908 to the timeout provided in the corresponding call to the
909 :meth:`Pool.acquire() <asyncpg.pool.Pool.acquire>` method.
910
911 .. versionchanged:: 0.14.0
912 Added the *timeout* parameter.
913 """
914 if (type(connection) is not PoolConnectionProxy or
915 connection._holder._pool is not self):
916 raise exceptions.InterfaceError(
917 'Pool.release() received invalid connection: '
918 '{connection!r} is not a member of this pool'.format(
919 connection=connection))
920
921 if connection._con is None:
922 # Already released, do nothing.
923 return
924
925 self._check_init()
926
927 # Let the connection do its internal housekeeping when its released.
928 connection._con._on_release()
929
930 ch = connection._holder
931 if timeout is None:
932 timeout = ch._timeout
933
934 # Use asyncio.shield() to guarantee that task cancellation
935 # does not prevent the connection from being returned to the
936 # pool properly.
937 return await asyncio.shield(ch.release(timeout))
938
939 async def close(self):
940 """Attempt to gracefully close all connections in the pool.

Callers 13

workerMethod · 0.45
test_pool_04Method · 0.45
test_pool_08Method · 0.45
test_pool_09Method · 0.45
test_pool_10Method · 0.45
workerMethod · 0.45

Calls 2

_check_initMethod · 0.95
_on_releaseMethod · 0.80

Tested by 12

workerMethod · 0.36
test_pool_04Method · 0.36
test_pool_08Method · 0.36
test_pool_09Method · 0.36
test_pool_10Method · 0.36
workerMethod · 0.36