thread safe extra network list_items

This commit is contained in:
w-e-w 2023-09-03 11:56:02 +09:00
parent d39440bfb9
commit aab385d01b
5 changed files with 16 additions and 12 deletions

View File

@ -66,11 +66,11 @@ class ExtraNetworksPageLora(ui_extra_networks.ExtraNetworksPage):
return item return item
def list_items(self): def list_items(self):
for index, name in enumerate(networks.available_networks): with self.thread_lock:
item = self.create_item(name, index) for index, name in enumerate(networks.available_networks):
item = self.create_item(name, index)
if item is not None: if item is not None:
yield item yield item
def allowed_directories_for_previews(self): def allowed_directories_for_previews(self):
return [shared.cmd_opts.lora_dir, shared.cmd_opts.lyco_dir_backcompat] return [shared.cmd_opts.lora_dir, shared.cmd_opts.lyco_dir_backcompat]

View File

@ -1,6 +1,7 @@
import os.path import os.path
import urllib.parse import urllib.parse
from pathlib import Path from pathlib import Path
from threading import Lock
from modules import shared, ui_extra_networks_user_metadata, errors, extra_networks from modules import shared, ui_extra_networks_user_metadata, errors, extra_networks
from modules.images import read_info_from_image, save_image_with_geninfo from modules.images import read_info_from_image, save_image_with_geninfo
@ -94,6 +95,7 @@ class ExtraNetworksPage:
self.allow_negative_prompt = False self.allow_negative_prompt = False
self.metadata = {} self.metadata = {}
self.items = {} self.items = {}
self.thread_lock = Lock()
def refresh(self): def refresh(self):
pass pass

View File

@ -30,9 +30,9 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
} }
def list_items(self): def list_items(self):
names = list(sd_models.checkpoints_list) with self.thread_lock:
for index, name in enumerate(names): for index, name in enumerate(sd_models.checkpoints_list):
yield self.create_item(name, index) yield self.create_item(name, index)
def allowed_directories_for_previews(self): def allowed_directories_for_previews(self):
return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None] return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]

View File

@ -31,8 +31,9 @@ class ExtraNetworksPageHypernetworks(ui_extra_networks.ExtraNetworksPage):
} }
def list_items(self): def list_items(self):
for index, name in enumerate(shared.hypernetworks): with self.thread_lock:
yield self.create_item(name, index) for index, name in enumerate(shared.hypernetworks):
yield self.create_item(name, index)
def allowed_directories_for_previews(self): def allowed_directories_for_previews(self):
return [shared.cmd_opts.hypernetwork_dir] return [shared.cmd_opts.hypernetwork_dir]

View File

@ -29,8 +29,9 @@ class ExtraNetworksPageTextualInversion(ui_extra_networks.ExtraNetworksPage):
} }
def list_items(self): def list_items(self):
for index, name in enumerate(sd_hijack.model_hijack.embedding_db.word_embeddings): with self.thread_lock:
yield self.create_item(name, index) for index, name in enumerate(sd_hijack.model_hijack.embedding_db.word_embeddings):
yield self.create_item(name, index)
def allowed_directories_for_previews(self): def allowed_directories_for_previews(self):
return list(sd_hijack.model_hijack.embedding_db.embedding_dirs) return list(sd_hijack.model_hijack.embedding_db.embedding_dirs)