MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / LimitedSizeQueue

Class LimitedSizeQueue

pywebio/utils.py:198–240  ·  view source on GitHub ↗

有限大小的队列 `get()` 返回全部数据 队列满时,再 `put()` 会阻塞

Source from the content-addressed store, hash-verified

196
197
198class LimitedSizeQueue(queue.Queue):
199 """
200 有限大小的队列
201
202 `get()` 返回全部数据
203 队列满时,再 `put()` 会阻塞
204 """
205
206 def get(self):
207 """获取队列全部数据"""
208 try:
209 return super().get(block=False)
210 except queue.Empty:
211 return []
212
213 def wait_empty(self, timeout=None):
214 """等待队列内的数据被取走"""
215 with self.not_full:
216 if self._qsize() == 0:
217 return
218
219 if timeout is None:
220 self.not_full.wait()
221 elif timeout < 0:
222 raise ValueError("'timeout' must be a non-negative number")
223 else:
224 self.not_full.wait(timeout)
225
226 def _init(self, maxsize):
227 self.queue = []
228
229 def _qsize(self):
230 return len(self.queue)
231
232 # Put a new item in the queue
233 def _put(self, item):
234 self.queue.append(item)
235
236 # Get an item from the queue
237 def _get(self):
238 all_data = self.queue
239 self.queue = []
240 return all_data
241
242
243async def wait_host_port(host, port, duration=10, delay=2):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…