Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

551 B
Raw Blame
"""Release optional stream resources without replacing an invocation error."""

import logging
from typing import Protocol, runtime_checkable

logger = logging.getLogger(__name__)


@runtime_checkable
class _Closable(Protocol):
    def close(self) -> None: ...


def close_stream(stream: object) -> None:
    """Close resource-owning streams; plain iterables need no cleanup."""
    if isinstance(stream, _Closable):
        try:
            stream.close()
        except Exception:
            logger.warning("Failed to close stream", exc_info=True)