import html import threading import time import cProfile from modules import shared, progress, errors queue_lock = threading.Lock() def wrap_queued_call(func): def f(*args, **kwargs): with queue_lock: res = func(*args, **kwargs) return res return f def wrap_gradio_gpu_call(func, extra_outputs=None): name = func.__name__ def f(*args, **kwargs): # if the first argument is a string that says "task(...)", it is treated as a job id if len(args) > 0 and type(args[0]) == str and args[0][0:5] == "task(" and args[0][-1] == ")": id_task = args[0] progress.add_task_to_queue(id_task) else: id_task = None with queue_lock: progress.start_task(id_task) res = [None, '', '', ''] try: res = func(*args, **kwargs) progress.record_results(id_task, res) except Exception as e: shared.log.error(f"Exception: {e}") shared.log.error(f"Arguments: args={str(args)[:10240]} kwargs={str(kwargs)[:10240]}") errors.display(e, 'gradio call') res[-1] = f"
" vram_html += f"GPU active {max(vram['active_peak'], vram['reserved_peak'])} MB reserved {vram['reserved']} | used {vram['used']} MB free {vram['free']} MB total {vram['total']} MB" vram_html += f" | retries {vram['retries']} oom {vram['oom']}" if vram.get('retries', 0) > 0 or vram.get('oom', 0) > 0 else '' vram_html += "
" if isinstance(res, list): res[-1] += f"Time: {elapsed_text}
{vram_html}