FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

'''A multi-producer, multi-consumer queue.''' import threading import types from collections import deque from heapq import heappush, heappop from time import monotonic as time try: from _queue import SimpleQueue except ImportError: SimpleQueue = None __all__ = [ 'Empty', 'Full', 'ShutDown', 'Queue', 'PriorityQueue', 'LifoQueue', 'SimpleQueue', ] try: from _queue import Empty except ImportError: class Empty(Exception): 'Exception raised by Queue.get(block=0)/get_nowait().' pass class Full(Exception): 'Exception raised by Queue.put(block=0)/put_nowait().' pass class ShutDown(Exception): '''Raised when put/get with shut-down queue.''' class Queue: '''Create a queue object with a given maximum size. If maxsize is = n as a direct substitute, but be aware that either approach risks a race condition where a queue can shrink before the result of full() or qsize() can be used. ''' with self.mutex: return 0 < self.maxsize 0: if not block: if self._qsize() >= self.maxsize: raise Full elif timeout is None: while self._qsize() >= self.maxsize: self.not_full.wait() if self.is_shutdown: raise ShutDown elif timeout < 0: raise ValueError("'timeout' must be a non-negative number") else: endtime = time() + timeout while self._qsize() >= self.maxsize: remaining = endtime - time() if remaining

Back | FazBrowse Home | New Git URL