diff options
author | Aarni Koskela <akx@iki.fi> | 2023-05-11 20:46:45 +0000 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2023-05-17 07:15:03 +0000 |
commit | 85b4f89926f7c3aaa7846dcbb47df3fd3b483b6b (patch) | |
tree | 716f033e712fe3eb7fa14bdfb6f8fe51836ae58c /webui.py | |
parent | 4b07f2f584596604c4499efb0b0295e96985080f (diff) | |
download | stable-diffusion-webui-gfx803-85b4f89926f7c3aaa7846dcbb47df3fd3b483b6b.tar.gz stable-diffusion-webui-gfx803-85b4f89926f7c3aaa7846dcbb47df3fd3b483b6b.tar.bz2 stable-diffusion-webui-gfx803-85b4f89926f7c3aaa7846dcbb47df3fd3b483b6b.zip |
Replace state.need_restart with state.server_command + replace poll loop with signal
Diffstat (limited to 'webui.py')
-rw-r--r-- | webui.py | 39 |
1 files changed, 24 insertions, 15 deletions
@@ -234,7 +234,10 @@ def initialize(): print(f'Interrupted with signal {sig} in {frame}')
os._exit(0)
- signal.signal(signal.SIGINT, sigint_handler)
+ if not os.environ.get("COVERAGE_RUN"):
+ # Don't install the immediate-quit handler when running under coverage,
+ # as then the coverage report won't be generated.
+ signal.signal(signal.SIGINT, sigint_handler)
def setup_middleware(app):
@@ -255,19 +258,6 @@ def create_api(app): return api
-def wait_on_server(demo=None):
- while 1:
- time.sleep(0.5)
- if shared.state.need_restart:
- shared.state.need_restart = False
- time.sleep(0.5)
- demo.close()
- time.sleep(0.5)
-
- modules.script_callbacks.app_reload_callback()
- break
-
-
def api_only():
initialize()
@@ -328,6 +318,7 @@ def webui(): inbrowser=cmd_opts.autolaunch,
prevent_thread_lock=True
)
+
# after initial launch, disable --autolaunch for subsequent restarts
cmd_opts.autolaunch = False
@@ -359,8 +350,26 @@ def webui(): redirector.get("/")
gradio.mount_gradio_app(redirector, shared.demo, path=f"/{cmd_opts.subpath}")
- wait_on_server(shared.demo)
+ try:
+ while True:
+ server_command = shared.state.wait_for_server_command(timeout=5)
+ if server_command:
+ if server_command in ("stop", "restart"):
+ break
+ else:
+ print(f"Unknown server command: {server_command}")
+ except KeyboardInterrupt:
+ server_command = "stop"
+
+ if server_command == "stop":
+ # If we catch a keyboard interrupt, we want to stop the server and exit.
+ print('Caught KeyboardInterrupt, stopping...')
+ shared.demo.close()
+ break
print('Restarting UI...')
+ shared.demo.close()
+ time.sleep(0.5)
+ modules.script_callbacks.app_reload_callback()
startup_timer.reset()
|