當前位置: 首頁>>代碼示例>>Python>>正文


Python Queue.Empty方法代碼示例

本文整理匯總了Python中Queue.Empty方法的典型用法代碼示例。如果您正苦於以下問題:Python Queue.Empty方法的具體用法?Python Queue.Empty怎麽用?Python Queue.Empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Queue的用法示例。


在下文中一共展示了Queue.Empty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: flow_mod_sender

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def flow_mod_sender(self):
        while self.run:
            try:
                flow_mod = self.flow_mod_queue.get(True, 0.5)
            except Empty:
                continue

            if self.timing:
                if self.simulation_start_time == 0:
                    self.real_start_time = time()
                    self.simulation_start_time = flow_mod["time"]

                sleep_time = self.sleep_time(flow_mod["time"])

                self.logger.debug('sleep for ' + str(sleep_time) + ' seconds')

                sleep(sleep_time)

            self.send(flow_mod) 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:21,代碼來源:log_client.py

示例2: sendHciCommand

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def sendHciCommand(self, opcode, data, timeout=2):
        """
        Send an arbitrary HCI packet by pushing a send-task into the
        sendQueue. This function blocks until the response is received
        or the timeout expires. The return value is the Payload of the
        HCI Command Complete Event which was received in response to
        the command or None if no response was received within the timeout.
        """

        queue = Queue.Queue(1)
        try:
            self.sendQueue.put((opcode, data, queue), timeout=timeout)
            return queue.get(timeout=timeout)
        except Queue.Empty:
            log.warn("sendHciCommand: waiting for response timed out!")
            return None
        except Queue.Full:
            log.warn("sendHciCommand: send queue is full!")
            return None 
開發者ID:francozappa,項目名稱:knob,代碼行數:21,代碼來源:core.py

示例3: recvPacket

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def recvPacket(self, timeout=None):
        """
        This function polls the recvQueue for the next available HCI
        packet and returns it. The function checks whether it is called
        from the sendThread or any other thread and respectively chooses
        either the sendThreadrecvQueue or the recvQueue.

        The recvQueue is filled by the recvThread. If the queue fills up
        the recvThread empties the queue (unprocessed packets are lost).
        The recvPacket function is meant to receive raw HCI packets in
        a blocking manner. Consider using the registerHciCallback()
        functionality as an alternative which works asynchronously.
        """

        if not self.check_running():
            return None

        try:
            return self.recvQueue.get(timeout=timeout)
        except Queue.Empty:
            return None 
開發者ID:francozappa,項目名稱:knob,代碼行數:23,代碼來源:core.py

示例4: launchRam

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def launchRam(self, address):
        """
        Executes a function at the specified address in the context of the HCI
        handler thread. The function has to comply with the calling convention.
        As the function blocks the HCI handler thread, the chip will most likely
        crash (or be resetted by Android) if the function takes too long.
        """
        

        response = self.sendHciCommand(0xfc4e, p32(address))
        if (response == None):
            log.warn("Empty HCI response during launchRam, driver crashed due to invalid code or destination")
            return False

        if(response[3] != '\x00'):
            log.warn("Got error code %x in command complete event." % response[3])
            return False
        
        # Nexus 6P Bugfix
        if ('LAUNCH_RAM_PAUSE' in dir(fw) and fw.LAUNCH_RAM_PAUSE):
            log.debug("launchRam: Bugfix, sleeping %ds" % fw.LAUNCH_RAM_PAUSE)
            time.sleep(fw.LAUNCH_RAM_PAUSE)
            
        return True 
開發者ID:francozappa,項目名稱:knob,代碼行數:26,代碼來源:core.py

示例5: reset

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def reset(self):
        """
        Resets the generator by stopping all processes
        """
        self.alive.value = False
        qsize = 0
        try:
            while True:
                self.queue.get(timeout=0.1)
                qsize += 1
        except QEmptyExcept:
            pass
        print("Queue size on reset: {}".format(qsize))
        for i, p in enumerate(self.proc):
            p.join()
        self.proc.clear() 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:18,代碼來源:multiproc_data.py

示例6: get_sizes

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def get_sizes(jsn):
   thrd = threading.current_thread()
   logging.info('starting thread '+str(thrd.ident)+' ...')
   try:
      while True:
         if queue.empty() == True: 
            break
         itm = queue.get()
         logging.info(str(thrd.ident)+' :' +str(itm))
         val = get_remote_size(itm)
         if val != None: jsn[itm]['objsize'] = val
         queue.task_done()
   except Queue.Empty: 
      pass
   logging.info('thread '+str(thrd.ident)+' done...') 
#get_sizes

#--------------------------------------------------------------------------------- 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:20,代碼來源:get_s3_stats.py

示例7: extractInfo

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def extractInfo(self):
        try:
            while not self.exit:
                try:
                    frame = self.frame_queue.get(block=True, timeout=1)
                except queue.Empty:
                    print("Queue empty")
                    continue
                try:
                    # Publish new image
                    msg = self.bridge.cv2_to_imgmsg(frame, 'rgb8')
                    if not self.exit:
                        self.image_publisher.publish(msg)
                except CvBridgeError as e:
                    print("Error Converting cv image: {}".format(e.message))
                self.frame_num += 1
        except Exception as e:
            print("Exception after loop: {}".format(e))
            raise 
開發者ID:sergionr2,項目名稱:RacingRobot,代碼行數:21,代碼來源:camera_node.py

示例8: _check_and_execute

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def _check_and_execute(self):
        wakeup_queue = self._wakeup_queue
        while 1:
            (next_expired_time, expired_timers) = self._get_expired_timers()
            for timer in expired_timers:
                try:
                    # Note, please make timer callback effective/short
                    timer()
                except Exception:
                    logging.error(traceback.format_exc())

            self._reset_timers(expired_timers)

            sleep_time = _calc_sleep_time(next_expired_time)
            try:
                wakeup = wakeup_queue.get(timeout=sleep_time)
                if wakeup is TEARDOWN_SENTINEL:
                    break
            except Queue.Empty:
                pass
        logging.info('TimerQueue stopped.') 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:23,代碼來源:timer_queue.py

示例9: _check_ip_all

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def _check_ip_all(self):
        rows = self.session.query(Proxy).all()
        self.thread_pool = ThreadPool(thread_count=10 if not len(rows)/20 else len(rows)/20)
        for row in rows:
            self.thread_pool.add_func(self._check, ip=row.ip, port=row.port, save_to_queue=True)
        self.thread_pool.close()
        self.thread_pool.join()
        while True:
            if self.thread_pool.exit is True and self.result_queue.empty():
                break
            else:
                try:
                    res = self.result_queue.get_nowait()
                    ip = res[0]
                    port = res[1]
                    delay = res[3]
                    alive = res[2]
                    logger.info("IP {0} Connect {1}, time: {2:.2f}s".format(ip, "success", delay)) if alive \
                        else logger.error("IP {0} Connect failed.".format(ip))
                    self._update_db(ip, port, delay, alive)
                except Queue.Empty:
                    time.sleep(2) 
開發者ID:lightless233,項目名稱:Pansidong,代碼行數:24,代碼來源:ProxyManage.py

示例10: run

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def run(self):

        while True:

            try:
                item = self.queue.get(timeout=3)
            except Queue.Empty:
                break

            time = self.music_time if item[0] == 'Audio' else self.video_time

            if time and (not self.player.isPlayingVideo() or xbmc.getCondVisibility('VideoPlayer.Content(livetv)')):
                dialog("notification", heading="%s %s" % (_(33049), item[0]), message=item[1],
                       icon="{emby}", time=time, sound=False)

            self.queue.task_done()

            if window('emby_should_stop.bool'):
                break

        LOG.info("--<[ q:notify/%s ]", id(self))
        self.is_done = True 
開發者ID:MediaBrowser,項目名稱:plugin.video.emby,代碼行數:24,代碼來源:library.py

示例11: Shutdown

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def Shutdown(self):
    """Shutdown the thread pool.

    Tasks may remain unexecuted in the submit queue.
    """

    while not self.requeue.empty():
      try:
        unused_item = self.requeue.get_nowait()
        self.requeue.task_done()
      except Queue.Empty:

        pass
    for thread in self.__threads:
      thread.exit_flag = True
      self.requeue.put(_THREAD_SHOULD_EXIT)
    self.__thread_gate.EnableAllThreads() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:19,代碼來源:adaptive_thread_pool.py

示例12: doHandleMessages

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def doHandleMessages(self, limit = None):
        if not limit is None:
            messageCount = 0

        while True:
            try:
                command = self.messageQueue.get(True, self.waitTimeout)
                if command.name == "shutdown":
                    return False
                else:
                    self.doExecuteCommand(command)

                    if not limit is None:
                        messageCount += 1
                        if limit <= messageCount:
                            break

            except Empty, e:
                break
            except Exception, e:
                log.error(e) 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:23,代碼來源:rmCommandThread.py

示例13: run

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def run(self):
        while True:
            try:
                resource = self.q.get(block=True, timeout=3)
                spider = self.factory.create_spider(resource)
                addr_list = spider.run()
                self.nq.put(len(addr_list), block=True, timeout=3)
                for addr in addr_list:
                    self.cq.put(addr, block=True, timeout=3)
                    # print addr
                self.q.task_done()
            except Queue.Empty:
                break
            except Exception, e:
                print e
                pass 
開發者ID:bluedazzle,項目名稱:django-angularjs-blog,代碼行數:18,代碼來源:ProxyConsumer.py

示例14: fetch_data

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def fetch_data(self, smids, items, im_batch):
        with self.coord.stop_on_exception():
            while not self.coord.should_stop():
                data = {}
                try:
                    data_idx = self.queue_idx.get(timeout=0.5)
                except Empty:
                    self.logger.debug('Index queue empty - {:s}'.format(
                        current_thread().name))
                    continue

                view_idx = np.random.choice(
                    self.num_renders, size=(im_batch, ), replace=False)
                sid, mid = smids[data_idx]
                for i in items:
                    data[i] = self.load_func[i](sid, mid, view_idx)

                self.queue_data.put(data)
                if self.loop_data:
                    self.queue_idx.put(data_idx) 
開發者ID:akar43,項目名稱:lsm,代碼行數:22,代碼來源:shapenet.py

示例15: run

# 需要導入模塊: import Queue [as 別名]
# 或者: from Queue import Empty [as 別名]
def run(self):
        global VISITED, DOWNLOADED, QUEUE
        while True:
            try:
                currentURL = QUEUE.get()
            except Queue.Empty:
                continue

            lock.acquire()  # 獲取鎖來修改VISITED內容
            try:
                if currentURL in VISITED:
                    QUEUE.task_done()
                    continue
                else:
                    VISITED.append(currentURL)
            finally:
                lock.release()

            try:
                response = urllib2.urlopen(currentURL)
                data = response.read()
            except urllib2.HTTPError, e:    #將可能發生的錯誤記錄到日誌文件中
                with open(DOWNLOADLOG, 'a') as f:
                    f.write(str(e.code)+' error while parsing the URL:'+currentURL+'\n')
            except: 
開發者ID:WuLC,項目名稱:ThesaurusSpider,代碼行數:27,代碼來源:multiThreadDownload.py


注:本文中的Queue.Empty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。