MCPcopy Create free account
hub / github.com/ActiveState/code / Queue

Class Queue

recipes/Python/327082_Pseudo_threads_generators/recipe-327082.py:125–153  ·  view source on GitHub ↗

A FIFO queue. If the queue has a max size, the oldest item on the queue is dropped if that size id exceeded.

Source from the content-addressed store, hash-verified

123
124
125class Queue(object):
126 """A FIFO queue. If the queue has a max size, the oldest item on the
127 queue is dropped if that size id exceeded.
128 """
129
130 def __init__(self, size=0, dispose_oldest=True):
131 self._queue = []
132 self._size = size
133 self._dispose_oldest = dispose_oldest
134
135 def put(self, item):
136 """Put item on the queue. If the queue size is limited ...
137 """
138 if self._size > 0 and len(self._queue) >= self._size:
139 if self._dispose_oldest:
140 self.get()
141 else:
142 raise QueueFull
143
144 self._queue.insert(0, item)
145
146 def get(self):
147 """Get the oldest item off the queue.
148 QueueEmpty is raised if no items are left on the queue.
149 """
150 try:
151 return self._queue.pop()
152 except IndexError:
153 raise QueueEmpty
154
155
156if __name__ == '__main__':

Callers 15

recipe-327082.pyFile · 0.70
breadth_first_searchFunction · 0.50
recipe-577223.pyFile · 0.50
mainFunction · 0.50
__init__Method · 0.50
__init__Method · 0.50
selectMethod · 0.50
mainFunction · 0.50
__init__Method · 0.50
recipe-577959.pyFile · 0.50
crawlMethod · 0.50
serve_foreverMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected