def put(self, task, *args, **kwargs): """Schedule the given task for background execution if queue isn't full. """ if self.__q.unfinished_tasks > self.size - 1: raise Queue.Full() self.__q.put_nowait((task, args, kwargs)) self.__keep_busy = True
def test_periodic_buffered_action_queue_full(): queue = MagicMock() queue.put_nowait.side_effect = Queue.Full() pba = PeriodicBufferedAction(action=None) pba._queue = queue pba.log = MagicMock() pba.enqueue('stuff') pba.log.exception.assert_called_with( 'Fatal Error: is worker out of memory? Details: ')
def receive(self, message, **kwargs): ''' receive single message from interface ''' if self.exit.is_set(): return message['timestamp'] = int(time.time() * 1e6) try: self.q.put_nowait(message) self.qsize = max(self.qsize, self.q.qsize()) except Queue.Full: raise Queue.Full('vi buffer overflow')
def guider_display(self, data, pixelX, pixelY): try: DISPLAY_QUEUE.put_nowait((data, pixelX, pixelY)) I_CUT_QUEUE.put_nowait((data, pixelX, pixelY)) self.region_selection_data = data self.data_x = pixelX self.data_y = pixelY if options.debug: print 'def guider_display: put image into display Q' return ro.OK except Queue.Full(): print 'display Q put failed' return ro.ERROR
def handleArrival(self): aevent = self.scheduleEvent(0) hp.heappush(self.cal, aevent) if (self.es.busy == True): # mutual exclusion self.es.queue.put(aevent) if (Queue.Full(self.es.queue)): print "no!" self.ep.busy = False if (self.ep.busy == False): # mutual exclusion self.es.busy = True self.ep.busy = True # set delay to 0 # add 1 to number of delayed # make busy # schedule departure devent = self.scheduleEvent(1) hp.heappush(self.cal, devent)
def put(self, img, label, boxes, *args, **kwargs): #----------------------------------------------------------------------- # Check whether the params are consistent with the data we can store #----------------------------------------------------------------------- def check_consistency(name, arr, dtype, shape, byte_count): if type(arr) is not np.ndarray: raise ValueError(name + ' needs to be a numpy array') if arr.dtype != dtype: raise ValueError( '{}\'s elements need to be of type {} but is {}'.format( name, str(dtype), str(arr.dtype))) if arr.shape != shape: raise ValueError('{}\'s shape needs to be {} but is {}'.format( name, shape, arr.shape)) if len(arr.tobytes()) != byte_count: raise ValueError( '{}\'s byte count needs to be {} but is {}'.format( name, byte_count, len(arr.data))) check_consistency('img', img, self.img_dtype, self.img_shape, self.img_bc) check_consistency('label', label, self.label_dtype, self.label_shape, self.label_bc) #----------------------------------------------------------------------- # If we can not get the slot within timeout we are actually full, not # empty #----------------------------------------------------------------------- try: arr_id = self.array_queue.get(*args, **kwargs) except q.Empty: raise q.Full() #----------------------------------------------------------------------- # Copy the arrays into the shared pool #----------------------------------------------------------------------- self.array_pool[arr_id][0][:] = img self.array_pool[arr_id][1][:] = label self.queue.put((arr_id, boxes), *args, **kwargs)
def ScheduleWorker(self, *args): ''' First argument is worker (callable), following are arguments for callable ''' #! TIME CRITICAL ! if self.__WorkerQueue is None: raise striga.core.exception.StrigaRuntimeException("Executor is not started") #TODO: Measure how long worker stays in queue if len(args) < 1: raise striga.core.exception.StrigaRuntimeException("You must specify worker as callable (first argument to ScheduleWorker)") for i in range(10): try: self.__WorkerQueue.put(args, True, 1) return except Queue.Full: L.warning("Worker queue full (try #%d)" % i) raise Queue.Full("Worker queue is long-time full")
def put_nowait(self, value): with self.__lock: if len(self.__queue) > self.__maxSize: raise Queue.Full() self.__queue.append(value)
def put(self, e): with self._lock: if len(self.queue) > 0: raise Queue.Full() self.queue.append(e)
def put(self, item, block=True, timeout=None): return self._failOrWait(block, timeout, Queue.Full())