本文整理汇总了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()