Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
65ed4421
Commit
65ed4421
authored
Jan 06, 2023
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add callback for when the script is unloaded
parent
c9bded39
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
script_callbacks.py
modules/script_callbacks.py
+17
-1
webui.py
webui.py
+2
-0
No files found.
modules/script_callbacks.py
View file @
65ed4421
...
@@ -71,6 +71,7 @@ callback_map = dict(
...
@@ -71,6 +71,7 @@ callback_map = dict(
callbacks_before_component
=
[],
callbacks_before_component
=
[],
callbacks_after_component
=
[],
callbacks_after_component
=
[],
callbacks_image_grid
=
[],
callbacks_image_grid
=
[],
callbacks_script_unloaded
=
[],
)
)
...
@@ -171,6 +172,14 @@ def image_grid_callback(params: ImageGridLoopParams):
...
@@ -171,6 +172,14 @@ def image_grid_callback(params: ImageGridLoopParams):
report_exception
(
c
,
'image_grid'
)
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
):
def
add_callback
(
callbacks
,
fun
):
stack
=
[
x
for
x
in
inspect
.
stack
()
if
x
.
filename
!=
__file__
]
stack
=
[
x
for
x
in
inspect
.
stack
()
if
x
.
filename
!=
__file__
]
filename
=
stack
[
0
]
.
filename
if
len
(
stack
)
>
0
else
'unknown file'
filename
=
stack
[
0
]
.
filename
if
len
(
stack
)
>
0
else
'unknown file'
...
@@ -202,7 +211,7 @@ def on_app_started(callback):
...
@@ -202,7 +211,7 @@ def on_app_started(callback):
def
on_model_loaded
(
callback
):
def
on_model_loaded
(
callback
):
"""register a function to be called when the stable diffusion model is created; the model is
"""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
)
add_callback
(
callback_map
[
'callbacks_model_loaded'
],
callback
)
...
@@ -279,3 +288,10 @@ def on_image_grid(callback):
...
@@ -279,3 +288,10 @@ def on_image_grid(callback):
- params: ImageGridLoopParams - parameters to be used for grid creation. Can be modified.
- params: ImageGridLoopParams - parameters to be used for grid creation. Can be modified.
"""
"""
add_callback
(
callback_map
[
'callbacks_image_grid'
],
callback
)
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
)
webui.py
View file @
65ed4421
...
@@ -187,12 +187,14 @@ def webui():
...
@@ -187,12 +187,14 @@ def webui():
sd_samplers
.
set_samplers
()
sd_samplers
.
set_samplers
()
modules
.
script_callbacks
.
script_unloaded_callback
()
extensions
.
list_extensions
()
extensions
.
list_extensions
()
localization
.
list_localizations
(
cmd_opts
.
localizations_dir
)
localization
.
list_localizations
(
cmd_opts
.
localizations_dir
)
modelloader
.
forbid_loaded_nonbuiltin_upscalers
()
modelloader
.
forbid_loaded_nonbuiltin_upscalers
()
modules
.
scripts
.
reload_scripts
()
modules
.
scripts
.
reload_scripts
()
modules
.
script_callbacks
.
model_loaded_callback
(
shared
.
sd_model
)
modelloader
.
load_upscalers
()
modelloader
.
load_upscalers
()
for
module
in
[
module
for
name
,
module
in
sys
.
modules
.
items
()
if
name
.
startswith
(
"modules.ui"
)]:
for
module
in
[
module
for
name
,
module
in
sys
.
modules
.
items
()
if
name
.
startswith
(
"modules.ui"
)]:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment