From 7f4786f9dd991dbe2da1c97f87866029f5f9f7c2 Mon Sep 17 00:00:00 2001 From: Marc-Andre Ferland Date: Thu, 27 Oct 2022 20:27:21 -0400 Subject: [PATCH] Wait until device is fully ready before proceding. --- ui/sd_internal/task_manager.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ui/sd_internal/task_manager.py b/ui/sd_internal/task_manager.py index efc53c08..1d0535ab 100644 --- a/ui/sd_internal/task_manager.py +++ b/ui/sd_internal/task_manager.py @@ -20,6 +20,8 @@ ERR_LOCK_FAILED = ' failed to acquire lock within timeout.' LOCK_TIMEOUT = 15 # Maximum locking time in seconds before failing a task. # It's better to get an exception than a deadlock... ALWAYS use timeout in critical paths. +DEVICE_START_TIMEOUT = 60 # seconds - Maximum time to wait for a render device to init. + class SymbolClass(type): # Print nicely formatted Symbol names. def __repr__(self): return self.__qualname__ def __str__(self): return self.__name__ @@ -240,9 +242,6 @@ def thread_get_next_task(): def thread_render(device): global current_state, current_state_error, current_model_path from . import runtime - weak_thread_data[threading.current_thread()] = { - 'device': device - } try: runtime.device_init(device) except: @@ -367,8 +366,8 @@ def start_render_thread(device='auto'): rthread.daemon = True rthread.name = THREAD_NAME_PREFIX + device rthread.start() - timeout = LOCK_TIMEOUT - while not rthread.is_alive(): + timeout = DEVICE_START_TIMEOUT + while not rthread.is_alive() or not rthread in weak_thread_data or not 'device' in weak_thread_data[rthread]: if timeout <= 0: raise Exception('render_thread', rthread.name, 'failed to start before timeout or has crashed.') timeout -= 1 time.sleep(1)