Text header, comments and better validations.

This commit is contained in:
Marc-Andre Ferland 2022-10-18 23:58:55 -04:00
parent 53cdeeff03
commit 6098b196dc
3 changed files with 22 additions and 1 deletions

View File

@ -1,3 +1,9 @@
"""runtime.py: torch device owned by a thread.
Notes:
Avoid device switching, transfering all models will get too complex.
To use a diffrent device signal the current render device to exit
And then start a new clean thread for the new device.
"""
import json import json
import os, re import os, re
import traceback import traceback

View File

@ -1,3 +1,9 @@
"""task_manager.py: manage tasks dispatching and render threads.
Notes:
render_threads should be the only hard reference held by the manager to the threads.
Use weak_thread_data to store all other data using weak keys.
This will allow for garbage collection after the thread dies.
"""
import json import json
import traceback import traceback
@ -340,6 +346,11 @@ 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
while not rthread.is_alive():
if timeout <= 0: raise Exception('render_thread', rthread.name, 'failed to start before timeout or has crashed.')
timeout -= 1
time.sleep(1)
render_threads.append(rthread) render_threads.append(rthread)
finally: finally:
manager_lock.release() manager_lock.release()

View File

@ -1,3 +1,7 @@
"""server.py: FastAPI SD-UI Web Host.
Notes:
async endpoints always run on the main thread. Without they run on the thread pool.
"""
import json import json
import traceback import traceback
@ -343,7 +347,7 @@ config = getConfig()
async def check_status(): # Task to Validate user config shortly after startup. async def check_status(): # Task to Validate user config shortly after startup.
# Check that the loaded config.json yielded a server in a known valid state. # Check that the loaded config.json yielded a server in a known valid state.
# Issues found, try to fix and warn the user. # When issues are found, try to fix them when possible and warn the user.
device_count = 0 device_count = 0
for i in range(10): # Wait for devices to register and/or change names. for i in range(10): # Wait for devices to register and/or change names.
await asyncio.sleep(3) await asyncio.sleep(3)