当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.getint方法代码示例

本文整理汇总了Python中config.Configuration.getint方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.getint方法的具体用法?Python Configuration.getint怎么用?Python Configuration.getint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config.Configuration的用法示例。


在下文中一共展示了Configuration.getint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Scheduler

# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import getint [as 别名]
class Scheduler(object):
    """
    Class that is scheduling tasks in queue and executing processes. Maximum
    count of running processes is given by configuration. Next task is scheduled
    in occurence of two types of events:
    1. When some process is finished and count of running processes is lower
       than maximum.
    2. When timeout expires and count of running processes is lower than
       maximum. This is useful when user add smaller amount of files than
       available count to queue and ran conversion. And then added next files.
       In this case scheduler check new files and schedule tasks.

    When scheduler is selecting new task from queue, takes top row that is not
    marked as running. Then new process is started and task is marked as runnig.
    Task is removed from queue and according to status of process added to
    tasks_done, tasks_incomplete or tasks_failed after finish of process.

    Scheduler supports this operations: start, cancel, pause and resume. They
    are propagated to running processes. State of of scheduler could be checked
    by this properties: running, paused, cancelled.
    """
    def __init__(self, tasks_queue):
        """
        Store queue of tasks and set object's attributes.
        @param tasks_queue Queue, Queue of tasks
        """
        self.tasks_queue = tasks_queue

        self.logger = logging.getLogger(self.__class__.__name__)

        self._running = False
        self._paused = False
        self._cancelled = False
        self.processes = set()
        self.tasks_done = []
        self.tasks_incomplete = []
        self.tasks_failed = []

        self.scheduler = tx_task.LoopingCall(self.schedule_tasks)
        self.deferred = defer.Deferred()

        self.config = Configuration()

        self.processes_count = self.config.getint('scheduler',
                                                  'processes_count')
        self.logger.debug('Count of processes to run: %s', self.processes_count)

        self.scheduler_timeout = self.config.getint('scheduler',
                                                    'scheduler_timeout')
        self.logger.debug('Scheduler timeout: %s', self.scheduler_timeout)

    @property
    def running(self):
        return self._running

    @property
    def paused(self):
        return self._paused

    @property
    def cancelled(self):
        return self._cancelled

    def start(self):
        """
        Start scheduling of queue.
        @return t.i.d.Deferred, None
        """
        assert not self.running

        self._running = True

        self.reset_finished_tasks()

        self.logger.debug('Starting scheduler')
        d = self.scheduler.start(self.scheduler_timeout)

        def scheduler_stopped(res):
            """
            Called when LoopingCall is stopped. Reset scheduler state and
            callback deferred.
            """
            self.logger.debug('Scheduler stopped')

            # reset previous state
            self._running = False
            self._paused = False
            self._cancelled = False

            # set NEW deferred
            d, self.deferred = self.deferred, defer.Deferred()

            d.callback(None)

        d.addBoth(scheduler_stopped)

        return d

    def cancel(self):
        """
#.........这里部分代码省略.........
开发者ID:jakm,项目名称:VideoConvertor,代码行数:103,代码来源:scheduler.py


注:本文中的config.Configuration.getint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。