Best Python code snippet using localstack_python
Queue.py
Source:Queue.py
...43 finally:44 self.all_tasks_done.release()45 def qsize(self):46 self.mutex.acquire()47 n = self._qsize()48 self.mutex.release()49 return n50 def empty(self):51 self.mutex.acquire()52 n = not self._qsize()53 self.mutex.release()54 return n55 def full(self):56 self.mutex.acquire()57 n = 0 < self.maxsize == self._qsize()58 self.mutex.release()59 return n60 def put(self, item, block = True, timeout = None):61 self.not_full.acquire()62 try:63 if self.maxsize > 0:64 if not block:65 if self._qsize() == self.maxsize:66 raise Full67 elif timeout is None:68 while self._qsize() == self.maxsize:69 self.not_full.wait()70 elif timeout < 0:71 raise ValueError("'timeout' must be a positive number")72 else:73 endtime = _time() + timeout74 while self._qsize() == self.maxsize:75 remaining = endtime - _time()76 if remaining <= 0.0:77 raise Full78 self.not_full.wait(remaining)79 self._put(item)80 self.unfinished_tasks += 181 self.not_empty.notify()82 finally:83 self.not_full.release()84 def put_nowait(self, item):85 return self.put(item, False)86 def get(self, block = True, timeout = None):87 self.not_empty.acquire()88 try:89 if not block:90 if not self._qsize():91 raise Empty92 elif timeout is None:93 while not self._qsize():94 self.not_empty.wait()95 elif timeout < 0:96 raise ValueError("'timeout' must be a positive number")97 else:98 endtime = _time() + timeout99 while not self._qsize():100 remaining = endtime - _time()101 if remaining <= 0.0:102 raise Empty103 self.not_empty.wait(remaining)104 item = self._get()105 self.not_full.notify()106 return item107 finally:108 self.not_empty.release()109 def get_nowait(self):110 return self.get(False)111 def _init(self, maxsize):112 self.queue = deque()113 def _qsize(self, len = len):114 return len(self.queue)115 def _put(self, item):116 self.queue.append(item)117 def _get(self):118 return self.queue.popleft()119class PriorityQueue(Queue):120 def _init(self, maxsize):121 self.queue = []122 def _qsize(self, len = len):123 return len(self.queue)124 def _put(self, item, heappush = heapq.heappush):125 heappush(self.queue, item)126 def _get(self, heappop = heapq.heappop):127 return heappop(self.queue)128class LifoQueue(Queue):129 def _init(self, maxsize):130 self.queue = []131 def _qsize(self, len = len):132 return len(self.queue)133 def _put(self, item):134 self.queue.append(item)135 def _get(self):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!