本文整理汇总了Python中twitter.common.collections.OrderedDict.popitem方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.popitem方法的具体用法?Python OrderedDict.popitem怎么用?Python OrderedDict.popitem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twitter.common.collections.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.popitem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ThermosGCExecutor
# 需要导入模块: from twitter.common.collections import OrderedDict [as 别名]
# 或者: from twitter.common.collections.OrderedDict import popitem [as 别名]
#.........这里部分代码省略.........
% (task_id, self._task_id))
self._task_id = task_id
self.log('Launching garbage collection [task_id=%s]' % task_id)
self._start_time = retain_start
local_gc, remote_gc, _ = self.reconcile_states(self._driver, retain_tasks)
deleted_tasks = set(retain_tasks).intersection(self.garbage_collect(local_gc)) | remote_gc
if deleted_tasks:
self._driver.sendFrameworkMessage(thrift_serialize(
SchedulerMessage(deletedTasks=DeletedTasks(taskIds=deleted_tasks))))
self.send_update(
self._driver, task.task_id.value, mesos_pb2.TASK_FINISHED, 'Garbage collection finished.')
self.log('Garbage collection complete [task_id=%s]' % task_id)
self._task_id = self._start_time = None
def run(self):
"""Main GC executor event loop.
Periodically perform state reconciliation with the set of tasks provided
by the slave, and garbage collect orphaned tasks on the system.
"""
run_start = self._clock.time()
last_gc_run = self._clock.time()
def should_terminate():
now = self._clock.time()
if now > run_start + self.MAXIMUM_EXECUTOR_LIFETIME.as_(Time.SECONDS):
return True
if now > last_gc_run + self.MAXIMUM_EXECUTOR_WAIT.as_(Time.SECONDS):
return True
return self._stop_event.is_set()
while not should_terminate():
try:
_, (task, retain_tasks, retain_start) = self._gc_task_queue.popitem(0)
last_gc_run = retain_start
self._run_gc(task, retain_tasks, retain_start)
except KeyError: # no enqueued GC tasks
pass
if self._driver is not None:
self.clean_orphans(self._driver)
self._stop_event.wait(self.POLL_WAIT.as_(Time.SECONDS))
# shutdown
if self._driver is not None:
try:
prev_task_id, _ = self._gc_task_queue.popitem(0)
except KeyError: # no enqueued GC tasks
pass
else:
self.send_update(self._driver, prev_task_id, mesos_pb2.TASK_FINISHED,
'Garbage collection skipped - GC executor shutting down')
# TODO(jon) Remove this once external MESOS-243 is resolved.
self.log('Sleeping briefly to mitigate https://issues.apache.org/jira/browse/MESOS-243')
self._clock.sleep(self.PERSISTENCE_WAIT.as_(Time.SECONDS))
self._driver.stop()
""" Mesos Executor API methods follow """
def launchTask(self, driver, task):
"""Queue a new garbage collection run, and drop any currently-enqueued runs."""
if self._slave_id is None:
self._slave_id = task.slave_id.value
task_id = task.task_id.value
self.log('launchTask() got task_id: %s' % task_id)
if task_id == self._task_id: