ID EN
Contextlib

AsyncExitStack

Python 3.11 🇮🇩 Bahasa Indonesia

Manajer konteks asinkron, mirip dengan ExitStack, yang mendukung penggabungan manajer konteks sinkron dan asinkron, serta memiliki coroutine untuk logika pembersihan.

Syntax

PYTHON
class contextlib.AsyncExitStack

Contoh

Example 1
PYTHON
async with AsyncExitStack() as stack:
    connections = [await stack.enter_async_context(get_connection())
        for i in range(5)]
     All opened connections will automatically be released at the end of
     the async with statement, even if attempts to open a connection
     later in the list raise an exception.

See Also

asynchronous context manager ExitStack close() aclose() ExitStack.enter_context() TypeError AttributeError ExitStack.push()