本文整理汇总了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 ###########################
示例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 ###
################################################################################
示例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 ###
################################################################################
示例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)
示例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()
示例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()
示例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')
示例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")
示例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()
示例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
示例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 ###########################
示例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
示例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()
示例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()