From a33ef50da5d3e576c61ba54806ce6480dddce48a Mon Sep 17 00:00:00 2001 From: Luke Barr Date: Mon, 19 Aug 2019 13:56:54 -0500 Subject: [PATCH] Long startup time on Linux (#356) --- mainscripts/Trainer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mainscripts/Trainer.py b/mainscripts/Trainer.py index f170fcc..85a6d68 100644 --- a/mainscripts/Trainer.py +++ b/mainscripts/Trainer.py @@ -12,7 +12,7 @@ import cv2 import models from interact import interact as io -def trainerThread (s2c, c2s, args, device_args): +def trainerThread (s2c, c2s, e, args, device_args): while True: try: start_time = time.time() @@ -66,6 +66,7 @@ def trainerThread (s2c, c2s, args, device_args): else: previews = [( 'debug, press update for new', model.debug_one_iter())] c2s.put ( {'op':'show', 'previews': previews} ) + e.set() #Set the GUI Thread as Ready if model.is_first_run(): @@ -189,9 +190,12 @@ def main(args, device_args): s2c = queue.Queue() c2s = queue.Queue() - thread = threading.Thread(target=trainerThread, args=(s2c, c2s, args, device_args) ) + e = threading.Event() + thread = threading.Thread(target=trainerThread, args=(s2c, c2s, e, args, device_args) ) thread.start() + e.wait() #Wait for inital load to occur. + if no_preview: while True: if not c2s.empty(): @@ -291,7 +295,7 @@ def main(args, device_args): key_events = io.get_key_events(wnd_name) key, chr_key, ctrl_pressed, alt_pressed, shift_pressed = key_events[-1] if len(key_events) > 0 else (0,0,False,False,False) - + if key == ord('\n') or key == ord('\r'): s2c.put ( {'op': 'close'} ) elif key == ord('s'): @@ -321,4 +325,4 @@ def main(args, device_args): except KeyboardInterrupt: s2c.put ( {'op': 'close'} ) - io.destroy_all_windows() + io.destroy_all_windows() \ No newline at end of file