本文整理汇总了Python中Queue.PriorityQueue方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.PriorityQueue方法的具体用法?Python Queue.PriorityQueue怎么用?Python Queue.PriorityQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.PriorityQueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play_video2
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def play_video2(API, video_url = common.args.url, rtmp = True):
try:
qbitrate = common.args.quality
except:
qbitrate = None
video_url2 = 'stack://'
threads = []
segments = []
closedcaption = []
queue = PriorityQueue()
video_data = connection.getURL(API + 'playlists/%s/videos.json' % video_url)
video_tree = simplejson.loads(video_data)
video_item = video_tree['playlist']['videos']
for i in range(0, len(video_item)):
try:
threads.append(Thread(get_videos, queue, i, video_item[i], qbitrate, rtmp))
except Exception, e:
print "Exception: ", e
示例2: thirdMax
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def thirdMax(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
import Queue
pq = Queue.PriorityQueue(4)
check = set()
for n in nums:
if n in check:
continue
pq.put(n)
check.add(n)
if len(check) > 3:
check.remove(pq.get())
total = len(check)
while total < 3 and total > 1:
total -= 1
return pq.get()
示例3: dijkstra
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def dijkstra(no):
global distancias
fila = Queue.PriorityQueue()
distancias[no] = 0
par = (distancias[no], no)
fila.put(par)
while not fila.empty():
_, topo = fila.get()
if adjacentes[topo] != 0:
for peso, filho in adjacentes[topo]:
if distancias[filho] > distancias[topo] + peso:
distancias[filho] = distancias[topo] + peso
fila.put((distancias[filho], filho))
示例4: __init__
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def __init__(self, getPathCallback, loadedCallback):
self._getPathCallback = getPathCallback
self._loadedCallback = loadedCallback
self._active = threading.Event()
self._active.set()
self._currentFile = None
self._currentProgress = None
self._stop = False
self._queue = Queue.PriorityQueue()
self._worker = threading.Thread(target=self._work)
self._worker.daemon = True
self._worker.start()
示例5: __init__
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def __init__(self,g,rsgf_filename,profile):
self.g=g
self.rsgf_filename=rsgf_filename
self.profile=profile
self.bot=self.initialize_bot()
self.update_queue=Queue.PriorityQueue()
self.label_queue=Queue.Queue()
self.best_moves_queue=Queue.Queue()
self.move_zero=self.g.get_root()
self.no_variation_if_same_move=True
size=self.g.get_size()
log("size of the tree:", size)
self.size=size
self.no_variation_if_same_move=grp_config.getboolean('Analysis', 'NoVariationIfSameMove')
self.maxvariations=grp_config.getint("Analysis", "maxvariations")
self.stop_at_first_resign=False
self.cpu_lock=threading.Lock()
示例6: threaded_html_writer
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def threaded_html_writer(maxsize=25):
"""
Expects to be sent a tuple of (save_path, results_dict)
"""
messages = Queue.PriorityQueue(maxsize=maxsize)
def run_thread():
while True:
p, item = messages.get()
if item is GeneratorExit:
return
else:
save_path, results_dict = item
save_results_as_html(save_path, results_dict)
threading.Thread(target=run_thread).start()
try:
n = 0
while True:
item = (yield)
messages.put((n, item))
n -= 1
except GeneratorExit:
messages.put((1, GeneratorExit))
示例7: threaded_weights_writer
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def threaded_weights_writer(maxsize=25):
"""
Expects to be sent a tuple of (save_path, checkpoint_dict)
"""
messages = Queue.PriorityQueue(maxsize=maxsize)
def run_thread():
while True:
p, item = messages.get()
if item is GeneratorExit:
return
else:
save_path, items_dict = item
save_weights(save_path, items_dict)
threading.Thread(target=run_thread).start()
try:
n = 0
while True:
item = (yield)
messages.put((n, item))
n -= 1
except GeneratorExit:
messages.put((1, GeneratorExit))
示例8: threaded_checkpoint_writer
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def threaded_checkpoint_writer(maxsize=25):
"""
Expects to be sent a tuple of (save_path, checkpoint_dict)
"""
messages = Queue.PriorityQueue(maxsize=maxsize)
def run_thread():
while True:
p, item = messages.get()
if item is GeneratorExit:
return
else:
save_path, pickle_item = item
save_checkpoint(save_path, pickle_item)
threading.Thread(target=run_thread).start()
try:
n = 0
while True:
item = (yield)
messages.put((n, item))
n -= 1
except GeneratorExit:
messages.put((1, GeneratorExit))
示例9: __init__
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def __init__(self, delay_exe_thdnum, queue_exec_thdnum, name):
"""
init
"""
self._toal_thdnum = delay_exe_thdnum + queue_exec_thdnum
self._delay_exe_thdnu = delay_exe_thdnum
self._queue_exe_thdnum = queue_exec_thdnum
self._delay_queue = queue.PriorityQueue()
self._exec_queue = queue.PriorityQueue()
self._thdpool = threadpool.ThreadPool(
self._toal_thdnum, self._toal_thdnum,
name='executor_pool'
)
self._status = 0 # 0 inited, 1 running 2 stopping
log.info(
'Executor service inited, delay_exec thread num:%d,'
' exec thread num:%d' % (delay_exe_thdnum, queue_exec_thdnum)
)
self._name = '' if name is None else name
示例10: threaded_html_writer
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def threaded_html_writer(interp=True, maxsize=25):
"""
Expects to be sent a tuple of (save_path, results_dict)
"""
messages = Queue.PriorityQueue(maxsize=maxsize)
def run_thread():
while True:
p, item = messages.get()
if item is GeneratorExit:
return
else:
save_path, results_dict = item
save_results_as_html(save_path, results_dict)
threading.Thread(target=run_thread).start()
try:
n = 0
while True:
item = (yield)
messages.put((n, item))
n -= 1
except GeneratorExit:
messages.put((1, GeneratorExit))
示例11: deserialize
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def deserialize(str_data):
newinf = InfrastructureInfo()
dic = json.loads(str_data)
vm_list = dic['vm_list']
vm_master_id = dic['vm_master']
dic['vm_master'] = None
dic['vm_list'] = []
if dic['auth']:
dic['auth'] = Authentication.deserialize(dic['auth'])
if dic['radl']:
dic['radl'] = parse_radl(dic['radl'])
else:
dic['radl'] = RADL()
if 'extra_info' in dic and dic['extra_info'] and "TOSCA" in dic['extra_info']:
try:
dic['extra_info']['TOSCA'] = Tosca.deserialize(dic['extra_info']['TOSCA'])
except Exception:
del dic['extra_info']['TOSCA']
InfrastructureInfo.logger.exception("Error deserializing TOSCA document")
newinf.__dict__.update(dic)
newinf.cloud_connector = None
# Set the ConfManager object and the lock to the data loaded
newinf.cm = None
newinf.ctxt_tasks = PriorityQueue()
newinf.conf_threads = []
for vm_data in vm_list:
vm = VirtualMachine.deserialize(vm_data)
vm.inf = newinf
if vm.im_id == vm_master_id:
newinf.vm_master = vm
newinf.vm_list.append(vm)
newinf.adding = False
newinf.deleting = False
return newinf
示例12: stop
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def stop(self):
"""
Stop all the Ctxt threads
"""
# Stop the Ctxt thread if it is alive.
if self.cm and self.cm.isAlive():
self.cm.stop()
# kill all the ctxt processes in the VMs
for vm in self.get_vm_list():
vm.kill_check_ctxt_process()
# Create a new empty queue
with self._lock:
self.ctxt_tasks = PriorityQueue()
示例13: reset_ctxt_tasks
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def reset_ctxt_tasks(self):
with self._lock:
self.ctxt_tasks = PriorityQueue()
示例14: __init__
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def __init__(self, *args, **kwargs):
super(TwitchBufferedOutputStream, self).__init__(*args, **kwargs)
self.last_frame = np.ones((self.height, self.width, 3))
self.last_frame_time = None
self.next_video_send_time = None
self.frame_counter = 0
self.q_video = queue.PriorityQueue()
# don't call the functions directly, as they block on the first
# call
self.t = threading.Timer(0.0, self._send_video_frame)
self.t.daemon = True
self.t.start()
if self.audio_enabled:
# send audio at about the same rate as video
# this can be changed
self.last_audio = (np.zeros((int(AUDIORATE/self.fps), )),
np.zeros((int(AUDIORATE/self.fps), )))
self.last_audio_time = None
self.next_audio_send_time = None
self.audio_frame_counter = 0
self.q_audio = queue.PriorityQueue()
self.t = threading.Timer(0.0, self._send_audio)
self.t.daemon = True
self.t.start()
示例15: __init__
# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import PriorityQueue [as 别名]
def __init__(self, parent):
self.parent = parent
self.cfg = parent.cfg
self.mutationQueue = PriorityQueue()
self.processedQueueElements = list()