{"record":{"id":"c9b43d454123eef0","repo":"TheAlgorithms/Python","slug":"maximum-queue-size-is-100","errorCode":null,"errorMessage":"Maximum queue size is 100","messagePattern":"Maximum queue size is 100","errorType":"exception","errorClass":"OverflowError","httpStatus":null,"severity":"error","filePath":"data_structures/queues/priority_queue_using_list.py","lineNumber":84,"sourceCode":"    Priority 2: []\n    \"\"\"  # noqa: E501\n\n    def __init__(self):\n        self.queues = [\n            [],\n            [],\n            [],\n        ]\n\n    def enqueue(self, priority: int, data: int) -> None:\n        \"\"\"\n        Add an element to a queue based on its priority.\n        If the priority is invalid ValueError is raised.\n        If the queue is full an OverFlowError is raised.\n        \"\"\"\n        try:\n            if len(self.queues[priority]) >= 100:\n                raise OverflowError(\"Maximum queue size is 100\")\n            self.queues[priority].append(data)\n        except IndexError:\n            raise ValueError(\"Valid priorities are 0, 1, and 2\")\n\n    def dequeue(self) -> int:\n        \"\"\"\n        Return the highest priority element in FIFO order.\n        If the queue is empty then an under flow exception is raised.\n        \"\"\"\n        for queue in self.queues:\n            if queue:\n                return queue.pop(0)\n        raise UnderFlowError(\"All queues are empty\")\n\n    def __str__(self) -> str:\n        return \"\\n\".join(f\"Priority {i}: {q}\" for i, q in enumerate(self.queues))\n\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/queues/priority_queue_using_list.py#L66-L102","documentation":"Raised by FixedPriorityQueue.enqueue() (data_structures/queues/priority_queue_using_list.py:84) when the target priority bucket (a plain Python list) already holds 100 elements. Each of the three priority levels is hard-capped at 100 items in this demo implementation. Note this is the builtin OverflowError, raised inside a try that only catches IndexError, so it propagates untouched.","triggerScenarios":"Calling enqueue(priority, data) more than 100 times with the same priority value (0, 1, or 2) without intervening dequeue() calls.","commonSituations":"Bulk-loading more than 100 items into one priority class, forgetting that the cap is per-priority not global, or porting code from an unbounded queue.Queue.","solutions":["Dequeue from that priority bucket before enqueueing once it is full","Raise the hard-coded 100 limit in the source (it appears in both FixedPriorityQueue and ElementPriorityQueue) or replace the list with collections.deque with your own policy","Track occupancy yourself: skip or spill items when len(pq.queues[priority]) reaches 100"],"exampleFix":"// before\nfor task in tasks:\n    pq.enqueue(1, task)  # OverflowError at the 101st\n\n# after\nfor task in tasks:\n    if len(pq.queues[1]) >= 100:\n        pq.dequeue()\n    pq.enqueue(1, task)","handlingStrategy":"validation","validationCode":"if len(pq.queues[priority]) >= 100:\n    pq.dequeue()  # or reject/spill\npq.enqueue(priority, data)","typeGuard":null,"tryCatchPattern":"try:\n    pq.enqueue(priority, data)\nexcept OverflowError:\n    pq.dequeue()\n    pq.enqueue(priority, data)","preventionTips":["Remember the 100 cap is per-priority bucket, not global","Do not port unbounded queue.Queue workloads onto this demo class"],"tags":["queue","priority-queue","overflow","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}