aclosing Class — langchain Architecture
Architecture documentation for the aclosing class in aiter.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e6bc0551_fcf9_3580_0617_e22bd3477471["aclosing"] b33566b6_8971_bdf8_5db2_dd5a13740a1f["aiter.py"] e6bc0551_fcf9_3580_0617_e22bd3477471 -->|defined in| b33566b6_8971_bdf8_5db2_dd5a13740a1f efd3be6d_6745_0ec5_794d_c132b17f8a43["__init__()"] e6bc0551_fcf9_3580_0617_e22bd3477471 -->|method| efd3be6d_6745_0ec5_794d_c132b17f8a43 adbe4925_a3c0_cc2b_3d1f_48a952ff15e6["__aenter__()"] e6bc0551_fcf9_3580_0617_e22bd3477471 -->|method| adbe4925_a3c0_cc2b_3d1f_48a952ff15e6 93696114_1b15_8d49_6176_f9d0c557d069["__aexit__()"] e6bc0551_fcf9_3580_0617_e22bd3477471 -->|method| 93696114_1b15_8d49_6176_f9d0c557d069
Relationship Graph
Source Code
libs/core/langchain_core/utils/aiter.py lines 280–322
class aclosing(AbstractAsyncContextManager): # noqa: N801
"""Async context manager to wrap an `AsyncGenerator` that has a `aclose()` method.
Code like this:
```python
async with aclosing(<module>.fetch(<arguments>)) as agen:
<block>
```
...is equivalent to this:
```python
agen = <module>.fetch(<arguments>)
try:
<block>
finally:
await agen.aclose()
```
"""
def __init__(self, thing: AsyncGenerator[Any, Any] | AsyncIterator[Any]) -> None:
"""Create the context manager.
Args:
thing: The resource to wrap.
"""
self.thing = thing
@override
async def __aenter__(self) -> AsyncGenerator[Any, Any] | AsyncIterator[Any]:
return self.thing
@override
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None:
if hasattr(self.thing, "aclose"):
await self.thing.aclose()
Defined In
Source
Frequently Asked Questions
What is the aclosing class?
aclosing is a class in the langchain codebase, defined in libs/core/langchain_core/utils/aiter.py.
Where is aclosing defined?
aclosing is defined in libs/core/langchain_core/utils/aiter.py at line 280.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free