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


Python Thread.max_execution_time方法代码示例

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


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

示例1: main

# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import max_execution_time [as 别名]
def main():
    """Main program

    :return:
    """
    find_json(current_dir + path_sep + "json")
    threads = []
    try:
        while True:
            now = datetime.now()
            ts_now = time.time()
            tmp_threads = threads
            threads = []
            nb_threads = {}
            for t_thread in tmp_threads:
                if not t_thread._Thread__stopped:
                    if t_thread.max_execution_time <= 0 or ts_now - t_thread.ts_started <= t_thread.max_time_execution:
                        if t_thread.getName() in nb_threads:
                            nb_threads[t_thread.getName()] += 1
                        else:
                            nb_threads[t_thread.getName()] = 1
                        threads.append(t_thread)
                    else:
                        t_thread._stop()
            for event_handler in schedules:
                nb_execs = 0
                if event_handler.event_conf.name in nb_threads:
                    nb_execs = nb_threads[event_handler.event_conf.name]
                if event_handler.check_schedule(now) and (nb_execs < event_handler.event_conf.max_executions or
                                                          event_handler.event_conf.max_executions == 0):
                    t1 = Thread(target=event_handler.run_schedule)
                    t1.setName(event_handler.event_conf.name)
                    t1.max_execution_time = event_handler.event_conf.max_time_execution
                    t1.ts_started = time.time()
                    t1.start()
                    threads.append(t1)
            time.sleep(60 - datetime.now().second)
    except KeyboardInterrupt:
        # Ctrl + C stop all
        for observer in observers:
            observer.stop()
        for thread in threads:
            thread.stop()
    for observer in observers:
        observer.join()
    for thread in threads:
        thread.join()
开发者ID:cedricg92,项目名称:shirp,代码行数:49,代码来源:run_event_manager.py


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