From 35ab63f75204665751a58c4039a2ecbc98a5702a Mon Sep 17 00:00:00 2001 From: iperov Date: Sun, 5 May 2019 17:05:03 +0400 Subject: [PATCH] add launch prog by timer repeatedly for colab --- mainscripts/Trainer.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mainscripts/Trainer.py b/mainscripts/Trainer.py index 2d6505a..f170fcc 100644 --- a/mainscripts/Trainer.py +++ b/mainscripts/Trainer.py @@ -81,14 +81,23 @@ def trainerThread (s2c, c2s, args, device_args): last_save_time = time.time() + execute_programs = [ [x[0], x[1], time.time() ] for x in execute_programs ] + for i in itertools.count(0,1): if not debug: cur_time = time.time() for x in execute_programs: - prog_time, prog = x - if prog_time != 0 and (cur_time - start_time) >= prog_time: + prog_time, prog, last_time = x + exec_prog = False + if prog_time > 0 and (cur_time - start_time) >= prog_time: x[0] = 0 + exec_prog = True + elif prog_time < 0 and (cur_time - last_time) >= -prog_time: + x[2] = cur_time + exec_prog = True + + if exec_prog: try: exec(prog) except Exception as e: