当前位置: 首页>>代码示例>>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;未经允许,请勿转载。