microsoft/autogen · error · RuntimeError

is bound to a different event loop

Error message

{self!r} is bound to a different event loop

What it means

Error "{self!r} is bound to a different event loop" thrown in microsoft/autogen.

Solutions

  1. Create the queue on the same loop that consumes it

Example fix

Instantiate asyncio.Queue inside the running loop's context

When it happens

Trigger: Thrown at python/packages/autogen-core/src/autogen_core/_queue.py:24 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/29cced88242edd85. Report an issue: GitHub.

Appendix: source

Thrown at python/packages/autogen-core/src/autogen_core/_queue.py:24

import collections
import threading
from typing import Generic, TypeVar

_global_lock = threading.Lock()


class _LoopBoundMixin:
    _loop = None

    def _get_loop(self) -> asyncio.AbstractEventLoop:
        loop = asyncio.get_running_loop()

        if self._loop is None:
            with _global_lock:
                if self._loop is None:
                    self._loop = loop
        if loop is not self._loop:
            raise RuntimeError(f"{self!r} is bound to a different event loop")
        return loop


class QueueShutDown(Exception):
    """Raised when putting on to or getting from a shut-down Queue."""

    pass


T = TypeVar("T")


class Queue(_LoopBoundMixin, Generic[T]):
    def __init__(self, maxsize: int = 0):
        self._maxsize = maxsize
        self._getters = collections.deque[asyncio.Future[None]]()
        self._putters = collections.deque[asyncio.Future[None]]()
        self._unfinished_tasks = 0

View on GitHub (pinned to 027ecf0a37)