Skip to content

Commit

Permalink
Merge pull request AUTOMATIC1111#13014 from AUTOMATIC1111/thread-safe…
Browse files Browse the repository at this point in the history
…-extranetworks-list_items

thread safe extra network list_items
  • Loading branch information
AUTOMATIC1111 authored Nov 19, 2023
2 parents 6fac65f + 74b80e7 commit 337bc4a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
7 changes: 5 additions & 2 deletions extensions-builtin/Lora/ui_extra_networks_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def refresh(self):

def create_item(self, name, index=None, enable_filter=True):
lora_on_disk = networks.available_networks.get(name)
if lora_on_disk is None:
return

path, ext = os.path.splitext(lora_on_disk.filename)

Expand Down Expand Up @@ -66,9 +68,10 @@ def create_item(self, name, index=None, enable_filter=True):
return item

def list_items(self):
for index, name in enumerate(networks.available_networks):
# instantiate a list to protect against concurrent modification
names = list(networks.available_networks)
for index, name in enumerate(names):
item = self.create_item(name, index)

if item is not None:
yield item

Expand Down
8 changes: 7 additions & 1 deletion modules/ui_extra_networks_checkpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def refresh(self):

def create_item(self, name, index=None, enable_filter=True):
checkpoint: sd_models.CheckpointInfo = sd_models.checkpoint_aliases.get(name)
if checkpoint is None:
return

path, ext = os.path.splitext(checkpoint.filename)
return {
"name": checkpoint.name_for_extra,
Expand All @@ -32,9 +35,12 @@ def create_item(self, name, index=None, enable_filter=True):
}

def list_items(self):
# instantiate a list to protect against concurrent modification
names = list(sd_models.checkpoints_list)
for index, name in enumerate(names):
yield self.create_item(name, index)
item = self.create_item(name, index)
if item is not None:
yield item

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]
Expand Down
13 changes: 10 additions & 3 deletions modules/ui_extra_networks_hypernets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def refresh(self):
shared.reload_hypernetworks()

def create_item(self, name, index=None, enable_filter=True):
full_path = shared.hypernetworks[name]
full_path = shared.hypernetworks.get(name)
if full_path is None:
return

path, ext = os.path.splitext(full_path)
sha256 = sha256_from_cache(full_path, f'hypernet/{name}')
shorthash = sha256[0:10] if sha256 else None
Expand All @@ -31,8 +34,12 @@ def create_item(self, name, index=None, enable_filter=True):
}

def list_items(self):
for index, name in enumerate(shared.hypernetworks):
yield self.create_item(name, index)
# instantiate a list to protect against concurrent modification
names = list(shared.hypernetworks)
for index, name in enumerate(names):
item = self.create_item(name, index)
if item is not None:
yield item

def allowed_directories_for_previews(self):
return [shared.cmd_opts.hypernetwork_dir]
Expand Down
10 changes: 8 additions & 2 deletions modules/ui_extra_networks_textual_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def refresh(self):

def create_item(self, name, index=None, enable_filter=True):
embedding = sd_hijack.model_hijack.embedding_db.word_embeddings.get(name)
if embedding is None:
return

path, ext = os.path.splitext(embedding.filename)
return {
Expand All @@ -29,8 +31,12 @@ def create_item(self, name, index=None, enable_filter=True):
}

def list_items(self):
for index, name in enumerate(sd_hijack.model_hijack.embedding_db.word_embeddings):
yield self.create_item(name, index)
# instantiate a list to protect against concurrent modification
names = list(sd_hijack.model_hijack.embedding_db.word_embeddings)
for index, name in enumerate(names):
item = self.create_item(name, index)
if item is not None:
yield item

def allowed_directories_for_previews(self):
return list(sd_hijack.model_hijack.embedding_db.embedding_dirs)

0 comments on commit 337bc4a

Please sign in to comment.