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)
| 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. |