Acquire a database connection from the pool. :param float timeout: A timeout for acquiring a Connection. :return: An instance of :class:`~asyncpg.connection.Connection`. Can be used in an ``await`` expression or with an ``async with`` block. .. code-block:: python
(self, *, timeout=None)
| 850 | ) |
| 851 | |
| 852 | def acquire(self, *, timeout=None): |
| 853 | """Acquire a database connection from the pool. |
| 854 | |
| 855 | :param float timeout: A timeout for acquiring a Connection. |
| 856 | :return: An instance of :class:`~asyncpg.connection.Connection`. |
| 857 | |
| 858 | Can be used in an ``await`` expression or with an ``async with`` block. |
| 859 | |
| 860 | .. code-block:: python |
| 861 | |
| 862 | async with pool.acquire() as con: |
| 863 | await con.execute(...) |
| 864 | |
| 865 | Or: |
| 866 | |
| 867 | .. code-block:: python |
| 868 | |
| 869 | con = await pool.acquire() |
| 870 | try: |
| 871 | await con.execute(...) |
| 872 | finally: |
| 873 | await pool.release(con) |
| 874 | """ |
| 875 | return PoolAcquireContext(self, timeout) |
| 876 | |
| 877 | async def _acquire(self, timeout): |
| 878 | async def _acquire_impl(): |