aboutsummaryrefslogtreecommitdiffstats
path: root/modules/script_callbacks.py
diff options
context:
space:
mode:
authornoodleanon <122053346+noodleanon@users.noreply.github.com>2023-01-07 14:18:09 +0000
committerGitHub <noreply@github.com>2023-01-07 14:18:09 +0000
commit50e25362794d46cd9a55c70e953a8b4126fd42f7 (patch)
treeea528f29a7c967de32f08217c50d994eebb277b3 /modules/script_callbacks.py
parenteadd1bf06adbd7263875640a6446d3b0184d1561 (diff)
parent151233399c4b79934bdbb7c12a97eeb6499572fb (diff)
downloadstable-diffusion-webui-gfx803-50e25362794d46cd9a55c70e953a8b4126fd42f7.tar.gz
stable-diffusion-webui-gfx803-50e25362794d46cd9a55c70e953a8b4126fd42f7.tar.bz2
stable-diffusion-webui-gfx803-50e25362794d46cd9a55c70e953a8b4126fd42f7.zip
Merge branch 'AUTOMATIC1111:master' into img2img-api-scripts
Diffstat (limited to 'modules/script_callbacks.py')
-rw-r--r--modules/script_callbacks.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/modules/script_callbacks.py b/modules/script_callbacks.py
index de69fd9f..608c5300 100644
--- a/modules/script_callbacks.py
+++ b/modules/script_callbacks.py
@@ -71,6 +71,7 @@ callback_map = dict(
callbacks_before_component=[],
callbacks_after_component=[],
callbacks_image_grid=[],
+ callbacks_script_unloaded=[],
)
@@ -171,6 +172,14 @@ def image_grid_callback(params: ImageGridLoopParams):
report_exception(c, 'image_grid')
+def script_unloaded_callback():
+ for c in reversed(callback_map['callbacks_script_unloaded']):
+ try:
+ c.callback()
+ except Exception:
+ report_exception(c, 'script_unloaded')
+
+
def add_callback(callbacks, fun):
stack = [x for x in inspect.stack() if x.filename != __file__]
filename = stack[0].filename if len(stack) > 0 else 'unknown file'
@@ -202,7 +211,7 @@ def on_app_started(callback):
def on_model_loaded(callback):
"""register a function to be called when the stable diffusion model is created; the model is
- passed as an argument"""
+ passed as an argument; this function is also called when the script is reloaded. """
add_callback(callback_map['callbacks_model_loaded'], callback)
@@ -279,3 +288,10 @@ def on_image_grid(callback):
- params: ImageGridLoopParams - parameters to be used for grid creation. Can be modified.
"""
add_callback(callback_map['callbacks_image_grid'], callback)
+
+
+def on_script_unloaded(callback):
+ """register a function to be called before the script is unloaded. Any hooks/hijacks/monkeying about that
+ the script did should be reverted here"""
+
+ add_callback(callback_map['callbacks_script_unloaded'], callback)