本文整理汇总了Python中work_queue.WorkQueue.wait方法的典型用法代码示例。如果您正苦于以下问题:Python WorkQueue.wait方法的具体用法?Python WorkQueue.wait怎么用?Python WorkQueue.wait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类work_queue.WorkQueue
的用法示例。
在下文中一共展示了WorkQueue.wait方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QMaster
# 需要导入模块: from work_queue import WorkQueue [as 别名]
# 或者: from work_queue.WorkQueue import wait [as 别名]
class QMaster(threading.Thread):
def __init__(self, project, port, log_freq=600): # 600 seconds
"""Initialize the QMaster
Parameters
----------
project :
port : int
log_freq : int, optional
frequency to print info about the status of the work queue.
In units of seconds. Default is to print every 10 minutes.
"""
threading.Thread.__init__(self)
self.project = project
self.log_freq = log_freq # print time in seconds
self.wake_freq = 1 # seconds
self.wq = WorkQueue(port, name='MSMAccelerator', catalog=True, exclusive=False)
logger.info('WORK QUEUE MASTER LISTENING ON PORT: %d', self.wq.port)
logger.info('(Start a local worker with >> work_queue_worker -d all localhost %d & )', self.wq.port)
# method controls whether or not we need to bring back solvated_xtc as well
if self.project.method == 'explicit':
self.return_wet_xtc = True
elif self.project.method == 'implicit':
self.return_wet_xtc = False
else:
raise Exception("project.method must be 'explicit' or 'implicit'")
logger.info('Return wet xtc set to %s', self.return_wet_xtc)
# what does this specify algorithm do?
self.wq.specify_algorithm(WORK_QUEUE_SCHEDULE_FCFS)
# fast abort kills jobs that appear to be stragling (taking more than 1.5x average)
#self.wq.activate_fast_abort(1.5)
# setting the stop event signals for the thread to die
self._stop = threading.Event()
# the thread sets the event every time a job returns or there are no waiting jobs
# and it finished post processing. See the wait method
self._mainloop_wake_event_cause = None
self._mainloop_wake_event = threading.Event()
# start the thread
self.start()
def run(self):
"""Main thread-loop for the QMaster thread"""
last_print = time.time()
while True:
time.sleep(self.wake_freq)
if not self.wq.empty():
t = self.wq.wait(self.wake_freq)
if t:
if t.return_status != 0:
logger.error('Worker returned nonzero exit status for job: %d', t.return_status)
else:
self.on_return(t)
self._mainloop_wake_event_cause = 'job returned'
self._mainloop_wake_event.set()
if self.wq.stats.tasks_waiting == 0 and not self._mainloop_wake_event.is_set():
self._mainloop_wake_event_cause = 'queue empty'
self._mainloop_wake_event.set() # also set the event if there are no tasks in the queue
if self._stop.is_set():
logger.info('Recieved stop signal. Shutting down all workers')
self.wq.shutdown_workers(0) # 0 indicates to shut all of them down
sys.exit(0)
if time.time() - last_print > self.log_freq:
logger.info('workers initialized: %d, ready: %d, busy: %d', self.wq.stats.workers_init, self.wq.stats.workers_ready, self.wq.stats.workers_busy)
logger.info('workers running: %d, waiting: %d, complete: %d', self.wq.stats.tasks_running, self.wq.stats.tasks_waiting, self.wq.stats.tasks_complete)
last_print = time.time()
def num_jobs_waiting(self):
"""Number of jobs waiting to be sent out
This number should be kept at 1, and when it drops to zero a new job
should be generated.
Returns
-------
n : int
The number
"""
return self.wq.stats.tasks_waiting
def num_jobs_in_queue(self):
"""Get the number of jobs currently in the work queue
This includes both the jobs running remotely and the ones waiting
here
#.........这里部分代码省略.........
示例2: range
# 需要导入模块: from work_queue import WorkQueue [as 别名]
# 或者: from work_queue.WorkQueue import wait [as 别名]
print task.command, task.algorithm
task.specify_buffer('hello from %d' % i, ifile, cache=False)
if i % 2:
task.specify_output_file(ofile, cache=False)
else:
task.specify_file(ofile, type=WORK_QUEUE_OUTPUT, cache=False)
outputs.append(ofile)
wq.submit(task)
if wq.empty():
print 'work queue is empty'
while not wq.empty():
t = wq.wait(10)
if t:
print t.tag
print wq.stats.workers_init, wq.stats.workers_ready, wq.stats.workers_busy, \
wq.stats.tasks_running, wq.stats.tasks_waiting, wq.stats.tasks_complete
map(os.unlink, outputs)
for i in range(5):
task = Task('hostname && date +%s.%N')
task.specify_input_file('/bin/hostname')
wq.submit(task)
if wq.hungry():
print 'work queue is hungry'