AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
142.95k stars 26.94k forks source link

[Bug]: Reload script (body only) does not work #9139

Open liudibo opened 1 year ago

liudibo commented 1 year ago

Is there an existing issue for this?

What happened?

  1. Reloading controlnet script throws an exception
  2. (Filtered the controlnet script). After changing the custom script and clicking the reload script button, the script logic is not changed.

Steps to reproduce the problem

  1. Change a custom script code
  2. Press "Reload script" button
  3. Run the script again

What should have happened?

  1. No exception
  2. The script run the new logic

Commit where the problem happens

22bcc7be428c94e9408f589966c2040187245d81

What platforms do you use to access the UI ?

Windows

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

NA

List of extensions

ControlNet

Console logs

To create a public link, set `share=True` in `launch()`.
Startup time: 2.2s (list extensions: 0.7s, load scripts: 0.3s, create ui: 1.1s).
Traceback (most recent call last):
  File "F:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 337, in run_predict
    output = await app.get_blocks().process_api(
  File "F:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1015, in process_api
    result = await self.call_function(
  File "F:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 833, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "F:\AI\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "F:\AI\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "F:\AI\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "F:\AI\stable-diffusion-webui\modules\ui.py", line 1515, in reload_scripts
    modules.scripts.reload_script_body_only()
  File "F:\AI\stable-diffusion-webui\modules\scripts.py", line 502, in reload_script_body_only
    cache = {}
  File "F:\AI\stable-diffusion-webui\modules\scripts.py", line 483, in reload_sources
    print(script.filename)
  File "F:\AI\stable-diffusion-webui\modules\script_loading.py", line 11, in load_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "F:\AI\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\controlnet.py", line 21, in <module>
    importlib.reload(global_state)
  File "E:\Python\3\lib\importlib\__init__.py", line 168, in reload
    raise ModuleNotFoundError(f"spec not found for the module {name!r}", name=name)
ModuleNotFoundError: spec not found for the module 'scripts.global_state'

Additional information

I have no idea about the controlnet.py.

I try to fix the reloading bug by assigning the reloaded script to self.selectable_scripts[si] just after self.scripts[si].

Praecordi commented 1 year ago

I'm having a similar issue but with scripts.processing instead. I'm running commit a3ddf464a2ed24c999f67ddfef7969f8291567be.

Here's the entire traceback for reference

Traceback (most recent call last):
  File "D:\SD\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 422, in run_predict
    output = await app.get_blocks().process_api(
  File "D:\SD\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "D:\SD\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1051, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\SD\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "D:\SD\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "D:\SD\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "D:\SD\stable-diffusion-webui\modules\ui_settings.py", line 213, in reload_scripts
    scripts.reload_script_body_only()
  File "D:\SD\stable-diffusion-webui\modules\scripts.py", line 597, in reload_script_body_only
    scripts_txt2img.reload_sources(cache)
  File "D:\SD\stable-diffusion-webui\modules\scripts.py", line 569, in reload_sources
    module = script_loading.load_module(script.filename)
  File "D:\SD\stable-diffusion-webui\modules\script_loading.py", line 10, in load_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\SD\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\controlnet.py", line 14, in <module>
    importlib.reload(processor)
  File "C:\Program Files\Python310\lib\importlib\__init__.py", line 168, in reload
    raise ModuleNotFoundError(f"spec not found for the module {name!r}", name=name)
ModuleNotFoundError: spec not found for the module 'scripts.processor'