Commit 12171ca9 authored by AUTOMATIC1111's avatar AUTOMATIC1111
Browse files

fix memory leak when generation fails

parent 56236dfd
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -3,7 +3,7 @@ import html
import threading
import threading
import time
import time


from modules import shared, progress, errors
from modules import shared, progress, errors, devices


queue_lock = threading.Lock()
queue_lock = threading.Lock()


@@ -75,6 +75,8 @@ def wrap_gradio_call(func, extra_outputs=None, add_stats=False):
            error_message = f'{type(e).__name__}: {e}'
            error_message = f'{type(e).__name__}: {e}'
            res = extra_outputs_array + [f"<div class='error'>{html.escape(error_message)}</div>"]
            res = extra_outputs_array + [f"<div class='error'>{html.escape(error_message)}</div>"]


        devices.torch_gc()

        shared.state.skipped = False
        shared.state.skipped = False
        shared.state.interrupted = False
        shared.state.interrupted = False
        shared.state.job_count = 0
        shared.state.job_count = 0
+2 −1
Original line number Original line Diff line number Diff line
@@ -14,7 +14,8 @@ def record_exception():
    if exception_records and exception_records[-1] == e:
    if exception_records and exception_records[-1] == e:
        return
        return


    exception_records.append((e, tb))
    from modules import sysinfo
    exception_records.append(sysinfo.format_exception(e, tb))


    if len(exception_records) > 5:
    if len(exception_records) > 5:
        exception_records.pop(0)
        exception_records.pop(0)
+5 −1
Original line number Original line Diff line number Diff line
@@ -109,11 +109,15 @@ def format_traceback(tb):
    return [[f"{x.filename}, line {x.lineno}, {x.name}", x.line] for x in traceback.extract_tb(tb)]
    return [[f"{x.filename}, line {x.lineno}, {x.name}", x.line] for x in traceback.extract_tb(tb)]




def format_exception(e, tb):
    return {"exception": str(e), "traceback": format_traceback(tb)}


def get_exceptions():
def get_exceptions():
    try:
    try:
        from modules import errors
        from modules import errors


        return [{"exception": str(e), "traceback": format_traceback(tb)} for e, tb in reversed(errors.exception_records)]
        return list(reversed(errors.exception_records))
    except Exception as e:
    except Exception as e:
        return str(e)
        return str(e)