mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-06 17:57:40 +08:00
Fix concurrency issues in AssetSeeder
- Fix race in mark_missing_outside_prefixes: set state to RUNNING inside lock before operations, restore to IDLE in finally block to prevent concurrent start() calls - Fix timing consistency: capture perf_counter before _update_progress for consistent event timing Amp-Thread-ID: https://ampcode.com/threads/T-019c354b-e7d7-7309-aa0e-79e5e7dff2b7 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
parent
5f0eb0432c
commit
93068c0d6d
@ -197,7 +197,9 @@ class AssetSeeder:
|
|||||||
"Cannot mark missing assets while scan is running"
|
"Cannot mark missing assets while scan is running"
|
||||||
)
|
)
|
||||||
return 0
|
return 0
|
||||||
|
self._state = State.RUNNING
|
||||||
|
|
||||||
|
try:
|
||||||
if not dependencies_available():
|
if not dependencies_available():
|
||||||
logging.warning(
|
logging.warning(
|
||||||
"Database dependencies not available, skipping mark missing"
|
"Database dependencies not available, skipping mark missing"
|
||||||
@ -209,6 +211,9 @@ class AssetSeeder:
|
|||||||
if marked > 0:
|
if marked > 0:
|
||||||
logging.info("Marked %d cache states as missing", marked)
|
logging.info("Marked %d cache states as missing", marked)
|
||||||
return marked
|
return marked
|
||||||
|
finally:
|
||||||
|
with self._lock:
|
||||||
|
self._state = State.IDLE
|
||||||
|
|
||||||
def _is_cancelled(self) -> bool:
|
def _is_cancelled(self) -> bool:
|
||||||
"""Check if cancellation has been requested."""
|
"""Check if cancellation has been requested."""
|
||||||
@ -362,9 +367,9 @@ class AssetSeeder:
|
|||||||
logging.exception("Batch insert failed at offset %d", i)
|
logging.exception("Batch insert failed at offset %d", i)
|
||||||
|
|
||||||
scanned = i + len(batch)
|
scanned = i + len(batch)
|
||||||
|
now = time.perf_counter()
|
||||||
self._update_progress(scanned=scanned, created=total_created)
|
self._update_progress(scanned=scanned, created=total_created)
|
||||||
|
|
||||||
now = time.perf_counter()
|
|
||||||
if now - last_progress_time >= progress_interval:
|
if now - last_progress_time >= progress_interval:
|
||||||
self._emit_event(
|
self._emit_event(
|
||||||
"assets.seed.progress",
|
"assets.seed.progress",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user