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


Python Executor.service_flag方法代码示例

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


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

示例1: main

# 需要导入模块: from executor import Executor [as 别名]
# 或者: from executor.Executor import service_flag [as 别名]
def main():
    parser = OptionParser()
    parser.add_option('-o', '--output', dest='output',
                      help='write messages to FILE', metavar='FILE')
    parser.add_option('-c', '--config', dest='config',
                      help='read config from FILE', metavar='FILE')
    parser.add_option('-d', '--debug', dest='debug', action='store_true',
                      help='print debug messages')
    parser.add_option('-v', '--version', dest='version', action='store_true',
                      help='print version number and exit')
    (options, args) = parser.parse_args()

    if options.version:
        print VERSION
        sys.exit(0)

    if not options.config:
        print >> sys.stderr, 'ERROR: Please provide a config file.'
        print parser.print_help()
        sys.exit(1)

    # Logging
    logger = logging.getLogger('Remidomo')
    if options.output:
        handler = logging.FileHandler(options.output)
    else:
        handler = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    handler.setFormatter(formatter)
    if options.debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    logger.addHandler(handler)

    # Main loop
    logger.info('Démarrage')

    config_timestamp = None
    rfx_listener = None
    while 1:
        file_timestamp = os.path.getmtime(options.config)
        if config_timestamp is None or config_timestamp != file_timestamp:
            if rfx_listener is not None:
                rfx_listener.stop()
                time.sleep(15)
            config = Config(logger)
            config.read_file(options.config)
            database = Database(config, logger)
            database.connect()
            executor = Executor(config, logger)
            rfx_listener = RFXListener(config, database, executor, logger)
            rfx_listener.start()
            config_timestamp = file_timestamp
            executor.service_flag(1)

        try:
            executor.blink_activity()
            check_orders(logger, config, executor, database)
            if not rfx_listener.isAlive():
                raise Exception('RFX thread stopped')
            time.sleep(60)
        except KeyboardInterrupt:
            print >> sys.stderr, '\nExiting by user request.\n'
            executor.heating_poweroff()
            executor.service_flag(0)
            rfx_listener.stop()
            database.close()
            sys.exit(0)
        except Exception, e:
            logger.warning('Emergency shutdown ! %s' % e)
            executor.heating_poweroff()
            executor.service_flag(0)
            # If main thread crashes, we must also stop RFX thread !
            rfx_listener.stop()
            database.close()
            raise
开发者ID:Remsouf,项目名称:meta-remidomo,代码行数:79,代码来源:remidomo.py


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