mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-02-18 11:20:58 +01:00
Wait until device is fully ready before proceding.
This commit is contained in:
parent
0dfaf9159d
commit
7f4786f9dd
@ -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.
|
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.
|
# 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.
|
class SymbolClass(type): # Print nicely formatted Symbol names.
|
||||||
def __repr__(self): return self.__qualname__
|
def __repr__(self): return self.__qualname__
|
||||||
def __str__(self): return self.__name__
|
def __str__(self): return self.__name__
|
||||||
@ -240,9 +242,6 @@ def thread_get_next_task():
|
|||||||
def thread_render(device):
|
def thread_render(device):
|
||||||
global current_state, current_state_error, current_model_path
|
global current_state, current_state_error, current_model_path
|
||||||
from . import runtime
|
from . import runtime
|
||||||
weak_thread_data[threading.current_thread()] = {
|
|
||||||
'device': device
|
|
||||||
}
|
|
||||||
try:
|
try:
|
||||||
runtime.device_init(device)
|
runtime.device_init(device)
|
||||||
except:
|
except:
|
||||||
@ -367,8 +366,8 @@ def start_render_thread(device='auto'):
|
|||||||
rthread.daemon = True
|
rthread.daemon = True
|
||||||
rthread.name = THREAD_NAME_PREFIX + device
|
rthread.name = THREAD_NAME_PREFIX + device
|
||||||
rthread.start()
|
rthread.start()
|
||||||
timeout = LOCK_TIMEOUT
|
timeout = DEVICE_START_TIMEOUT
|
||||||
while not rthread.is_alive():
|
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.')
|
if timeout <= 0: raise Exception('render_thread', rthread.name, 'failed to start before timeout or has crashed.')
|
||||||
timeout -= 1
|
timeout -= 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user