Clean-up Ctrl+C Shutdown (#4802)

This commit is contained in:
erew123 2023-12-05 05:16:16 +00:00 committed by GitHub
parent 0f828ea441
commit f786aa3caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import hashlib
import os import os
import platform import platform
import re import re
import signal
import site import site
import subprocess import subprocess
import sys import sys
@ -27,6 +28,13 @@ else:
flags = f"{' '.join([flag for flag in sys.argv[1:] if flag != '--update'])} {CMD_FLAGS}" flags = f"{' '.join([flag for flag in sys.argv[1:] if flag != '--update'])} {CMD_FLAGS}"
def signal_handler(sig, frame):
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def is_linux(): def is_linux():
return sys.platform.startswith("linux") return sys.platform.startswith("linux")

View File

@ -21,6 +21,7 @@ matplotlib.use('Agg') # This fixes LaTeX rendering on some systems
import json import json
import os import os
import signal
import sys import sys
import time import time
from functools import partial from functools import partial
@ -55,6 +56,17 @@ from modules.models_settings import (
from modules.utils import gradio from modules.utils import gradio
def signal_handler(sig, frame):
logger.info(f"Received Ctrl+C. Shutting down Text generation web UI gracefully")
if 'interface' in shared.gradio:
shared.gradio['interface'].close()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def create_interface(): def create_interface():
title = 'Text generation web UI' title = 'Text generation web UI'