当前位置: 首页>>代码示例>>Python>>正文


Python queue.empty方法代码示例

本文整理汇总了Python中queue.empty方法的典型用法代码示例。如果您正苦于以下问题:Python queue.empty方法的具体用法?Python queue.empty怎么用?Python queue.empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在queue的用法示例。


在下文中一共展示了queue.empty方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decode

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def decode(queue, log_probs, decoder, index2label):
    while not queue.empty():
        try:
            video = queue.get(timeout = 3)
            score, labels, segments = decoder.decode( log_probs[video] )
            # save result
            with open('results/' + video, 'w') as f:
                f.write( '### Recognized sequence: ###\n' )
                f.write( ' '.join( [index2label[s.label] for s in segments] ) + '\n' )
                f.write( '### Score: ###\n' + str(score) + '\n')
                f.write( '### Frame level recognition: ###\n')
                f.write( ' '.join( [index2label[l] for l in labels] ) + '\n' )
        except queue.Empty:
            pass


### read label2index mapping and index2label mapping ########################### 
开发者ID:alexanderrichard,项目名称:NeuralNetwork-Viterbi,代码行数:19,代码来源:inference.py

示例2: monte_carlo_grammar

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def monte_carlo_grammar(dataset, mean_lengths, index2label, max_paths = 1000):
    monte_carlo_grammar = []
    sil_length = mean_lengths[0]
    while len(monte_carlo_grammar) < max_paths:
        for video in dataset.videos():
            action_set = dataset.action_set[video] - set([0]) # exclude SIL
            seq = []
            while sum( [ mean_lengths[label] for label in seq ] ) + 2 * sil_length < dataset.length(video):
                seq.append( random.choice(list(action_set)) )
            if len(seq) == 0: # omit empty sequences
                continue
            monte_carlo_grammar.append('SIL ' + ' '.join( [index2label[idx] for idx in seq] ) + ' SIL')
    random.shuffle(monte_carlo_grammar)
    return monte_carlo_grammar[0:max_paths]


################################################################################
### TRAINING                                                                 ###
################################################################################ 
开发者ID:alexanderrichard,项目名称:action-sets,代码行数:21,代码来源:main.py

示例3: decode

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def decode(queue, log_probs, decoder, index2label):
    while not queue.empty():
        try:
            video = queue.get(timeout = 3)
            score, labels, segments = decoder.decode( log_probs[video] )
            # save result
            with open('results/' + video, 'w') as f:
                f.write( '### Recognized sequence: ###\n' )
                f.write( ' '.join( [index2label[s.label] for s in segments] ) + '\n' )
                f.write( '### Score: ###\n' + str(score) + '\n')
                f.write( '### Frame level recognition: ###\n')
                f.write( ' '.join( [index2label[l] for l in labels] ) + '\n' )
        except queue.Empty:
            pass



################################################################################
### MAIN                                                                     ###
################################################################################ 
开发者ID:alexanderrichard,项目名称:action-sets,代码行数:22,代码来源:main.py

示例4: mySubscriber

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def mySubscriber(queue):
  while not queue.empty():
    item = queue.get()
    if item is None:
      break
    print("{} removed {} from the queue".format(threading.current_thread(), item))
    queue.task_done()
    time.sleep(1) 
开发者ID:PacktPublishing,项目名称:Learning-Concurrency-in-Python,代码行数:10,代码来源:queues.py

示例5: mySubscriber

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def mySubscriber(queue):
  while not queue.empty():
    item = queue.get()
    if item is None:
      break
    print("{} removed {} from the queue".format(threading.current_thread(), item))
    queue.task_done() 
开发者ID:PacktPublishing,项目名称:Learning-Concurrency-in-Python,代码行数:9,代码来源:lifoQueues.py

示例6: mySubscriber

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def mySubscriber(queue):
  time.sleep(1)
  while not queue.empty():
    item = queue.get()
    if item is None:
      break
    print("{} removed {} from the queue".format(threading.current_thread(), item))
    queue.task_done() 
开发者ID:PacktPublishing,项目名称:Learning-Concurrency-in-Python,代码行数:10,代码来源:queueJoin.py

示例7: worker

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def worker(c):
    thread = threading.currentThread()
    if queue.empty():
        return
    json_file = queue.get()
    config = json_file.replace(".json","")
    c.run(config)
    worker(c)
    queue.task_done()
    logging.debug('Done') 
开发者ID:HyperGAN,项目名称:HyperGAN,代码行数:12,代码来源:run_all.py

示例8: time_connection

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def time_connection(self, server, queue):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.connect(server)
            print("Conncted to " + str(server))
            if queue.empty:
                queue.put(server)
            s.close()
        except:
            print(str(server) + "does not respond") 
开发者ID:P2PSP,项目名称:simulator,代码行数:12,代码来源:balancer.py

示例9: async_write

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def async_write(buffer=[]):
    item = queue.get()
    buffer.append(item)
    if len(buffer) > 500 or queue.empty():
        log.debug('Processing {} queue items.'.format(len(buffer)))
        with db.transaction():
            write_buffer(buffer)
        buffer.clear() 
开发者ID:anqxyr,项目名称:pyscp,代码行数:10,代码来源:orm.py

示例10: decode

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def decode(queue, log_probs, decoder, index2label):
    while not queue.empty():
        try:
            video = queue.get(timeout = 3)
            score, labels, segments = decoder.decode( log_probs[video] )
            # save result
            with open('results/' + video, 'w') as f:
                f.write( '### Recognized sequence: ###\n' )
                f.write( ' '.join( [index2label[s.label] for s in segments] ) + '\n' )
                f.write( '### Score: ###\n' + str(score) + '\n')
                f.write( '### Frame level recognition: ###\n')
                f.write( ' '.join( [index2label[l] for l in labels] ) + '\n' )
        except queue.Empty:
            pass 
开发者ID:JunLi-Galios,项目名称:CDFL,代码行数:16,代码来源:inference.py

示例11: stn_decode

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def stn_decode(queue, log_probs, decoder, index2label, window, step):
    while not queue.empty():
        try:
            video = queue.get(timeout = 3)
            score, labels, segments = decoder.decode( log_probs[video])
#             cum_segments = np.array([segment.length for segment in segments])
#             cum_segments = np.cumsum(cum_segments)
#             print('segments', cum_segments)
#             print('labels', len(labels))
#             labels = np.array(labels)
            trancript = [s.label for s in segments]
#             print('trancript', trancript)
            stn_score, stn_labels, stn_segments = decoder.stn_decode( log_probs[video], segments, trancript, window, step)
#             stn_labels2 =  [s.label for s in stn_segments]
#             print('stn_labels2', stn_labels2)
#             print('stn_labels', len(stn_labels))
#             cum_segments = np.array([stn_segment.length for stn_segment in stn_segments])
#             cum_segments = np.cumsum(cum_segments)
#             print('stn_segments', cum_segments)
            # save result
            with open('results/' + video, 'w') as f:
                f.write( '### Recognized sequence: ###\n' )
                f.write( ' '.join( [index2label[s.label] for s in stn_segments] ) + '\n' )
                f.write( '### Score: ###\n' + str(stn_score) + '\n')
                f.write( '### Frame level recognition: ###\n')
                f.write( ' '.join( [index2label[l] for l in stn_labels] ) + '\n' )
        except queue.Empty:
            pass


### read label2index mapping and index2label mapping ########################### 
开发者ID:JunLi-Galios,项目名称:CDFL,代码行数:33,代码来源:inference.py

示例12: _dequeue

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def _dequeue(self, queue):
        """Removes queue entries till an alive reference was found.
        The referenced image holder will be returned in this case.
        Otherwise if there wasn't found any alive reference
        None will be returned.

        Args:
            queue (queue.Queue): the queue to operate on

        Returns:
            tuple of (ImageHolder, tuple of (width: int, height: int),
                      PostLoadImageProcessor):
                an queued image holder or None, upper bound size or None,
                the post load image processor or None
        """
        holder_reference = None
        image_holder = None
        upper_bound_size = None
        post_load_processor = None

        while not queue.empty():
            holder_reference, upper_bound_size, post_load_processor = \
                queue.get_nowait()
            image_holder = holder_reference and holder_reference()
            if (holder_reference is None or
                    image_holder is not None):
                break

        return image_holder, upper_bound_size, post_load_processor 
开发者ID:seebye,项目名称:ueberzug,代码行数:31,代码来源:loading.py

示例13: __wait_for_main_work

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def __wait_for_main_work(self):
        """Waits till all queued high priority entries were processed."""
        if not self.__queue.empty():
            with self.__waiter_low_priority:
                if not self.__queue.empty():
                    self.__waiter_low_priority.wait() 
开发者ID:seebye,项目名称:ueberzug,代码行数:8,代码来源:loading.py

示例14: __notify_main_work_done

# 需要导入模块: import queue [as 别名]
# 或者: from queue import empty [as 别名]
def __notify_main_work_done(self):
        """Notifies waiting threads that
        all queued high priority entries were processed.
        """
        if self.__queue.empty():
            with self.__waiter_low_priority:
                if self.__queue.empty():
                    self.__waiter_low_priority.notify_all() 
开发者ID:seebye,项目名称:ueberzug,代码行数:10,代码来源:loading.py


注:本文中的queue.empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。