本文整理汇总了Python中threading.Thread.ts_started方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.ts_started方法的具体用法?Python Thread.ts_started怎么用?Python Thread.ts_started使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threading.Thread
的用法示例。
在下文中一共展示了Thread.ts_started方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import ts_started [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()