diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-06-05 17:06:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 17:06:40 +0000 |
commit | 1dd8d571a4fa053633314657c78032a5b83a7cb5 (patch) | |
tree | 3b6c643d969e1dd164fbee5d835ab02d0a47d487 | |
parent | 18acc0b30d9184702a772287ed8197385e0aed98 (diff) | |
parent | 46a5bd64edece07f521409f0adace6cdd6f30a40 (diff) | |
download | stable-diffusion-webui-gfx803-1dd8d571a4fa053633314657c78032a5b83a7cb5.tar.gz stable-diffusion-webui-gfx803-1dd8d571a4fa053633314657c78032a5b83a7cb5.tar.bz2 stable-diffusion-webui-gfx803-1dd8d571a4fa053633314657c78032a5b83a7cb5.zip |
Merge pull request #11043 from akx/restart-envvar
Restart: only do restart if running via the wrapper script
-rw-r--r-- | modules/restart.py | 23 | ||||
-rw-r--r-- | modules/shared.py | 9 | ||||
-rw-r--r-- | modules/ui_extensions.py | 11 | ||||
-rw-r--r-- | webui.bat | 2 | ||||
-rwxr-xr-x | webui.sh | 1 |
5 files changed, 33 insertions, 13 deletions
diff --git a/modules/restart.py b/modules/restart.py new file mode 100644 index 00000000..18eacaf3 --- /dev/null +++ b/modules/restart.py @@ -0,0 +1,23 @@ +import os +from pathlib import Path + +from modules.paths_internal import script_path + + +def is_restartable() -> bool: + """ + Return True if the webui is restartable (i.e. there is something watching to restart it with) + """ + return bool(os.environ.get('SD_WEBUI_RESTART')) + + +def restart_program() -> None: + """creates file tmp/restart and immediately stops the process, which webui.bat/webui.sh interpret as a command to start webui again""" + + (Path(script_path) / "tmp" / "restart").touch() + + stop_program() + + +def stop_program() -> None: + os._exit(0) diff --git a/modules/shared.py b/modules/shared.py index 2bd7c6ec..c9ee2dd1 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -853,12 +853,3 @@ def walk_files(path, allowed_extensions=None): continue
yield os.path.join(root, filename)
-
-
-def restart_program():
- """creates file tmp/restart and immediately stops the process, which webui.bat/webui.sh interpret as a command to start webui again"""
-
- with open(os.path.join(script_path, "tmp", "restart"), "w"):
- pass
-
- os._exit(0)
diff --git a/modules/ui_extensions.py b/modules/ui_extensions.py index 1ae516d7..4379a641 100644 --- a/modules/ui_extensions.py +++ b/modules/ui_extensions.py @@ -11,7 +11,7 @@ import html import shutil
import errno
-from modules import extensions, shared, paths, config_states, errors
+from modules import extensions, shared, paths, config_states, errors, restart
from modules.paths_internal import config_states_dir
from modules.call_queue import wrap_gradio_gpu_call
@@ -49,7 +49,11 @@ def apply_and_restart(disable_list, update_list, disable_all): shared.opts.disabled_extensions = disabled
shared.opts.disable_all_extensions = disable_all
shared.opts.save(shared.config_filename)
- shared.restart_program()
+
+ if restart.is_restartable():
+ restart.restart_program()
+ else:
+ restart.stop_program()
def save_config_state(name):
@@ -509,7 +513,8 @@ def create_ui(): with gr.TabItem("Installed", id="installed"):
with gr.Row(elem_id="extensions_installed_top"):
- apply = gr.Button(value="Apply and restart UI", variant="primary")
+ apply_label = ("Apply and restart UI" if restart.is_restartable() else "Apply and quit")
+ apply = gr.Button(value=apply_label, variant="primary")
check = gr.Button(value="Check for updates")
extensions_disable_all = gr.Radio(label="Disable all extensions", choices=["none", "extra", "all"], value=shared.opts.disable_all_extensions, elem_id="extensions_disable_all")
extensions_disabled_list = gr.Text(elem_id="extensions_disabled_list", visible=False).style(container=False)
@@ -3,7 +3,7 @@ if not defined PYTHON (set PYTHON=python)
if not defined VENV_DIR (set "VENV_DIR=%~dp0%venv")
-
+set SD_WEBUI_RESTART=tmp/restart
set ERROR_REPORTING=FALSE
mkdir tmp 2>NUL
@@ -204,6 +204,7 @@ prepare_tcmalloc() { } KEEP_GOING=1 +export SD_WEBUI_RESTART=tmp/restart while [[ "$KEEP_GOING" -eq "1" ]]; do if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]; then printf "\n%s\n" "${delimiter}" |