TheAlgorithms/Python · error · OverflowError
Maximum queue size is 100
Error message
Maximum queue size is 100
What it means
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.
Source
Thrown at data_structures/queues/priority_queue_using_list.py:84
Priority 2: []
""" # noqa: E501
def __init__(self):
self.queues = [
[],
[],
[],
]
def enqueue(self, priority: int, data: int) -> None:
"""
Add an element to a queue based on its priority.
If the priority is invalid ValueError is raised.
If the queue is full an OverFlowError is raised.
"""
try:
if len(self.queues[priority]) >= 100:
raise OverflowError("Maximum queue size is 100")
self.queues[priority].append(data)
except IndexError:
raise ValueError("Valid priorities are 0, 1, and 2")
def dequeue(self) -> int:
"""
Return the highest priority element in FIFO order.
If the queue is empty then an under flow exception is raised.
"""
for queue in self.queues:
if queue:
return queue.pop(0)
raise UnderFlowError("All queues are empty")
def __str__(self) -> str:
return "\n".join(f"Priority {i}: {q}" for i, q in enumerate(self.queues))
View on GitHub (pinned to f5988cc097)
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
Example fix
// before
for task in tasks:
pq.enqueue(1, task) # OverflowError at the 101st
# after
for task in tasks:
if len(pq.queues[1]) >= 100:
pq.dequeue()
pq.enqueue(1, task) Defensive patterns
Strategy: validation
Validate before calling
if len(pq.queues[priority]) >= 100:
pq.dequeue() # or reject/spill
pq.enqueue(priority, data) Try / catch
try:
pq.enqueue(priority, data)
except OverflowError:
pq.dequeue()
pq.enqueue(priority, data) Prevention
- Remember the 100 cap is per-priority bucket, not global
- Do not port unbounded queue.Queue workloads onto this demo class
When it happens
Trigger: Calling enqueue(priority, data) more than 100 times with the same priority value (0, 1, or 2) without intervening dequeue() calls.
Common situations: 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.
Related errors
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/c9b43d454123eef0.
Report an issue: GitHub.