當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。