Skip to content

IOStream

autogen.io.IOStream #

A protocol for input/output streams.

set_global_default staticmethod #

set_global_default(stream)

Set the default input/output stream.

PARAMETER DESCRIPTION
stream

The input/output stream to set as the default.

TYPE: IOStream

Source code in autogen/io/base.py
@staticmethod
def set_global_default(stream: iostream_union) -> None:
    """Set the default input/output stream.

    Args:
        stream (IOStream): The input/output stream to set as the default.
    """
    IOStream._global_default = stream

get_global_default staticmethod #

get_global_default()

Get the default input/output stream.

RETURNS DESCRIPTION
IOStream

The default input/output stream.

TYPE: iostream_union

Source code in autogen/io/base.py
@staticmethod
def get_global_default() -> iostream_union:
    """Get the default input/output stream.

    Returns:
        IOStream: The default input/output stream.
    """
    if IOStream._global_default is None:
        raise RuntimeError("No global default IOStream has been set")
    return IOStream._global_default

get_default staticmethod #

get_default()

Get the default input/output stream.

RETURNS DESCRIPTION
IOStream

The default input/output stream.

TYPE: iostream_union

Source code in autogen/io/base.py
@staticmethod
def get_default() -> iostream_union:
    """Get the default input/output stream.

    Returns:
        IOStream: The default input/output stream.
    """
    iostream = IOStream._default_io_stream.get()
    if iostream is None:
        iostream = IOStream.get_global_default()
        # Set the default IOStream of the current context (thread/cooroutine)
        IOStream.set_default(iostream)
    return iostream

set_default staticmethod #

set_default(stream)

Set the default input/output stream.

PARAMETER DESCRIPTION
stream

The input/output stream to set as the default.

TYPE: IOStream

Source code in autogen/io/base.py
@staticmethod
@contextmanager
def set_default(stream: Optional[iostream_union]) -> Iterator[None]:
    """Set the default input/output stream.

    Args:
        stream (IOStream): The input/output stream to set as the default.
    """
    global _default_io_stream
    try:
        token = IOStream._default_io_stream.set(stream)
        yield
    finally:
        IOStream._default_io_stream.reset(token)

    return