python runtime_error ai_generated true

asyncio.queues.QueueFull:

ID: python/asyncio-queue-bounded-full

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-09-24First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

Root Cause

put_nowait() was called on an asyncio.Queue whose maxsize was reached and no consumer was draining it, so the bounded queue rejected the item.

generic

中文

在已达 maxsize 的 asyncio.Queue 上调用 put_nowait(),且没有消费者在消费,导致有界队列拒绝该元素。

Workarounds

  1. 92% success
    q = asyncio.Queue(maxsize=100)
    async def producer():
        for item in items:
            await q.put(item)  # blocks when full, no QueueFull
  2. 88% success
    consumers = [asyncio.create_task(consume(q)) for _ in range(4)]
    await producer(q)
    await q.join()
    for c in consumers: c.cancel()

Dead Ends

Common approaches that don't work:

  1. 75% fail

    Defers the problem; under sustained producer-heavy load memory still grows unbounded.

  2. 80% fail

    Causes data loss with no visibility; downstream counters drift.