mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-17 02:12:58 +08:00
fixed: /manager/queue/status - race condition issue
This commit is contained in:
parent
829784fa50
commit
3c2933338f
@ -41,7 +41,7 @@ import manager_downloader
|
|||||||
from node_package import InstalledNodePackage
|
from node_package import InstalledNodePackage
|
||||||
|
|
||||||
|
|
||||||
version_code = [3, 13]
|
version_code = [3, 13, 1]
|
||||||
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
|
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -372,13 +372,16 @@ def nickname_filter(json_obj):
|
|||||||
task_queue = queue.Queue()
|
task_queue = queue.Queue()
|
||||||
nodepack_result = {}
|
nodepack_result = {}
|
||||||
model_result = {}
|
model_result = {}
|
||||||
|
tasks_in_progress = set()
|
||||||
|
task_worker_lock = threading.Lock()
|
||||||
|
|
||||||
async def task_worker():
|
async def task_worker():
|
||||||
global task_queue
|
global task_queue
|
||||||
global nodepack_result
|
global nodepack_result
|
||||||
global model_result
|
global model_result
|
||||||
|
global tasks_in_progress
|
||||||
|
|
||||||
async def do_install(item):
|
async def do_install(item) -> str:
|
||||||
ui_id, node_spec_str, channel, mode, skip_post_install = item
|
ui_id, node_spec_str, channel, mode, skip_post_install = item
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -386,8 +389,7 @@ async def task_worker():
|
|||||||
|
|
||||||
if node_spec is None:
|
if node_spec is None:
|
||||||
logging.error(f"Cannot resolve install target: '{node_spec_str}'")
|
logging.error(f"Cannot resolve install target: '{node_spec_str}'")
|
||||||
nodepack_result[ui_id] = f"Cannot resolve install target: '{node_spec_str}'"
|
return f"Cannot resolve install target: '{node_spec_str}'"
|
||||||
return
|
|
||||||
|
|
||||||
node_name, version_spec, is_specified = node_spec
|
node_name, version_spec, is_specified = node_spec
|
||||||
res = await core.unified_manager.install_by_id(node_name, version_spec, channel, mode, return_postinstall=skip_post_install)
|
res = await core.unified_manager.install_by_id(node_name, version_spec, channel, mode, return_postinstall=skip_post_install)
|
||||||
@ -395,20 +397,18 @@ async def task_worker():
|
|||||||
|
|
||||||
if res.action not in ['skip', 'enable', 'install-git', 'install-cnr', 'switch-cnr']:
|
if res.action not in ['skip', 'enable', 'install-git', 'install-cnr', 'switch-cnr']:
|
||||||
logging.error(f"[ComfyUI-Manager] Installation failed:\n{res.msg}")
|
logging.error(f"[ComfyUI-Manager] Installation failed:\n{res.msg}")
|
||||||
nodepack_result[ui_id] = res.msg
|
return res.msg
|
||||||
return
|
|
||||||
|
|
||||||
elif not res.result:
|
elif not res.result:
|
||||||
logging.error(f"[ComfyUI-Manager] Installation failed:\n{res.msg}")
|
logging.error(f"[ComfyUI-Manager] Installation failed:\n{res.msg}")
|
||||||
nodepack_result[ui_id] = res.msg
|
return res.msg
|
||||||
return
|
|
||||||
|
|
||||||
nodepack_result[ui_id] = 'success'
|
return 'success'
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
nodepack_result[ui_id] = f"Installation failed:\n{node_spec_str}"
|
return f"Installation failed:\n{node_spec_str}"
|
||||||
|
|
||||||
async def do_update(item):
|
async def do_update(item) -> str:
|
||||||
ui_id, node_name, node_ver = item
|
ui_id, node_name, node_ver = item
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -417,70 +417,68 @@ async def task_worker():
|
|||||||
manager_util.clear_pip_cache()
|
manager_util.clear_pip_cache()
|
||||||
|
|
||||||
if res.result:
|
if res.result:
|
||||||
nodepack_result[ui_id] = 'success'
|
return 'success'
|
||||||
return
|
|
||||||
|
|
||||||
logging.error(f"\nERROR: An error occurred while updating '{node_name}'.")
|
logging.error(f"\nERROR: An error occurred while updating '{node_name}'.")
|
||||||
nodepack_result[ui_id] = f"An error occurred while updating '{node_name}'."
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
nodepack_result[ui_id] = f"An error occurred while updating '{node_name}'."
|
|
||||||
|
|
||||||
async def do_fix(item):
|
return f"An error occurred while updating '{node_name}'."
|
||||||
|
|
||||||
|
async def do_fix(item) -> str:
|
||||||
ui_id, node_name, node_ver = item
|
ui_id, node_name, node_ver = item
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = core.unified_manager.unified_fix(node_name, node_ver)
|
res = core.unified_manager.unified_fix(node_name, node_ver)
|
||||||
|
|
||||||
if res.result:
|
if res.result:
|
||||||
nodepack_result[ui_id] = 'success'
|
return 'success'
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
logging.error(res.msg)
|
logging.error(res.msg)
|
||||||
|
|
||||||
logging.error(f"\nERROR: An error occurred while fixing '{node_name}@{node_ver}'.")
|
logging.error(f"\nERROR: An error occurred while fixing '{node_name}@{node_ver}'.")
|
||||||
nodepack_result[ui_id] = f"An error occurred while fixing '{node_name}@{node_ver}'."
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
nodepack_result[ui_id] = f"An error occurred while fixing '{node_name}@{node_ver}'."
|
|
||||||
|
|
||||||
async def do_uninstall(item):
|
return f"An error occurred while fixing '{node_name}@{node_ver}'."
|
||||||
|
|
||||||
|
async def do_uninstall(item) -> str:
|
||||||
ui_id, node_name, is_unknown = item
|
ui_id, node_name, is_unknown = item
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = core.unified_manager.unified_uninstall(node_name, is_unknown)
|
res = core.unified_manager.unified_uninstall(node_name, is_unknown)
|
||||||
|
|
||||||
if res.result:
|
if res.result:
|
||||||
nodepack_result[ui_id] = 'success'
|
return 'success'
|
||||||
return
|
|
||||||
|
|
||||||
logging.error(f"\nERROR: An error occurred while uninstalling '{node_name}'.")
|
logging.error(f"\nERROR: An error occurred while uninstalling '{node_name}'.")
|
||||||
nodepack_result[ui_id] = f"An error occurred while uninstalling '{node_name}'."
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
nodepack_result[ui_id] = f"An error occurred while uninstalling '{node_name}'."
|
|
||||||
|
|
||||||
async def do_disable(item):
|
return f"An error occurred while uninstalling '{node_name}'."
|
||||||
|
|
||||||
|
async def do_disable(item) -> str:
|
||||||
ui_id, node_name, is_unknown = item
|
ui_id, node_name, is_unknown = item
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = core.unified_manager.unified_disable(node_name, is_unknown)
|
res = core.unified_manager.unified_disable(node_name, is_unknown)
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
nodepack_result[ui_id] = 'success'
|
return 'success'
|
||||||
return
|
|
||||||
|
|
||||||
nodepack_result[ui_id] = f"Failed to disable: '{node_name}'"
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
nodepack_result[ui_id] = f"Failed to disable: '{node_name}'"
|
|
||||||
|
|
||||||
async def do_install_model(item):
|
return f"Failed to disable: '{node_name}'"
|
||||||
|
|
||||||
|
async def do_install_model(item) -> str:
|
||||||
ui_id, json_data = item
|
ui_id, json_data = item
|
||||||
|
|
||||||
model_path = get_model_path(json_data)
|
model_path = get_model_path(json_data)
|
||||||
model_url = json_data['url']
|
model_url = json_data['url']
|
||||||
|
|
||||||
|
res = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if model_path is not None:
|
if model_path is not None:
|
||||||
logging.info(f"Install model '{json_data['name']}' from '{model_url}' into '{model_path}'")
|
logging.info(f"Install model '{json_data['name']}' from '{model_url}' into '{model_path}'")
|
||||||
@ -494,24 +492,21 @@ async def task_worker():
|
|||||||
res = True
|
res = True
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
model_result[ui_id] = 'success'
|
return 'success'
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
res = download_url_with_agent(model_url, model_path)
|
res = download_url_with_agent(model_url, model_path)
|
||||||
if res and model_path.endswith('.zip'):
|
if res and model_path.endswith('.zip'):
|
||||||
res = core.unzip(model_path)
|
res = core.unzip(model_path)
|
||||||
else:
|
else:
|
||||||
logging.error(f"Model installation error: invalid model type - {json_data['type']}")
|
logging.error(f"Model installation error: invalid model type - {json_data['type']}")
|
||||||
return
|
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
model_result[ui_id] = 'success'
|
return 'success'
|
||||||
return
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"[ERROR] {e}", file=sys.stderr)
|
logging.error(f"[ERROR] {e}", file=sys.stderr)
|
||||||
|
|
||||||
model_result[ui_id] = f"Model installation error: {model_url}"
|
return f"Model installation error: {model_url}"
|
||||||
|
|
||||||
stats = {}
|
stats = {}
|
||||||
|
|
||||||
@ -529,32 +524,44 @@ async def task_worker():
|
|||||||
'total_count': total_count, 'done_count': done_count})
|
'total_count': total_count, 'done_count': done_count})
|
||||||
nodepack_result = {}
|
nodepack_result = {}
|
||||||
task_queue = queue.Queue()
|
task_queue = queue.Queue()
|
||||||
return
|
return # terminate worker thread
|
||||||
|
|
||||||
kind, item = task_queue.get()
|
with task_worker_lock:
|
||||||
|
kind, item = task_queue.get()
|
||||||
|
tasks_in_progress.add((kind, item[0]))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if kind == 'install':
|
if kind == 'install':
|
||||||
await do_install(item)
|
msg = await do_install(item)
|
||||||
if kind == 'install-model':
|
elif kind == 'install-model':
|
||||||
await do_install_model(item)
|
msg = await do_install_model(item)
|
||||||
elif kind == 'update':
|
elif kind == 'update':
|
||||||
await do_update(item)
|
msg = await do_update(item)
|
||||||
elif kind == 'fix':
|
elif kind == 'fix':
|
||||||
await do_fix(item)
|
msg = await do_fix(item)
|
||||||
elif kind == 'uninstall':
|
elif kind == 'uninstall':
|
||||||
await do_uninstall(item)
|
msg = await do_uninstall(item)
|
||||||
elif kind == 'disable':
|
elif kind == 'disable':
|
||||||
await do_disable(item)
|
msg = await do_disable(item)
|
||||||
|
else:
|
||||||
|
msg = "Unexpected kind: " + kind
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
msg = f"Exception: {(kind, item)}"
|
||||||
|
|
||||||
|
with task_worker_lock:
|
||||||
|
tasks_in_progress.remove((kind, item[0]))
|
||||||
|
|
||||||
|
ui_id = item[0]
|
||||||
|
if kind == 'install-model':
|
||||||
|
model_result[ui_id] = msg
|
||||||
|
ui_target = "model_manager"
|
||||||
|
else:
|
||||||
|
nodepack_result[ui_id] = msg
|
||||||
|
ui_target = "nodepack_manager"
|
||||||
|
|
||||||
stats[kind] = stats.get(kind, 0) + 1
|
stats[kind] = stats.get(kind, 0) + 1
|
||||||
|
|
||||||
ui_target = "model_manager" if kind == 'install-model' else 'nodepack_manager'
|
|
||||||
|
|
||||||
print(f"kind: {kind} / ui_target: {ui_target}")
|
|
||||||
|
|
||||||
PromptServer.instance.send_sync("cm-queue-status",
|
PromptServer.instance.send_sync("cm-queue-status",
|
||||||
{'status': 'in_progress', 'target': item[0], 'ui_target': ui_target,
|
{'status': 'in_progress', 'target': item[0], 'ui_target': ui_target,
|
||||||
'total_count': total_count, 'done_count': done_count})
|
'total_count': total_count, 'done_count': done_count})
|
||||||
@ -1073,11 +1080,15 @@ async def reset_queue(request):
|
|||||||
async def queue_count(request):
|
async def queue_count(request):
|
||||||
global task_queue
|
global task_queue
|
||||||
|
|
||||||
done_count = len(nodepack_result) + len(model_result)
|
with task_worker_lock:
|
||||||
total_count = done_count + task_queue.qsize()
|
done_count = len(nodepack_result) + len(model_result)
|
||||||
in_progress = task_worker_thread is not None and task_worker_thread.is_alive()
|
in_progress_count = len(tasks_in_progress)
|
||||||
|
total_count = done_count + in_progress_count + task_queue.qsize()
|
||||||
|
is_processing = task_worker_thread is not None and task_worker_thread.is_alive()
|
||||||
|
|
||||||
return web.json_response({'total_count': total_count, 'done_count': done_count, 'in_progress': in_progress})
|
return web.json_response({
|
||||||
|
'total_count': total_count, 'done_count': done_count, 'in_progress_count': in_progress_count,
|
||||||
|
'is_processing': is_processing})
|
||||||
|
|
||||||
|
|
||||||
@routes.post("/manager/queue/install")
|
@routes.post("/manager/queue/install")
|
||||||
@ -1129,7 +1140,7 @@ async def install_custom_node(request):
|
|||||||
return web.Response(status=200)
|
return web.Response(status=200)
|
||||||
|
|
||||||
|
|
||||||
task_worker_thread = None
|
task_worker_thread:threading.Thread = None
|
||||||
|
|
||||||
@routes.get("/manager/queue/start")
|
@routes.get("/manager/queue/start")
|
||||||
async def queue_start(request):
|
async def queue_start(request):
|
||||||
|
|||||||
@ -1287,7 +1287,7 @@ export class CustomNodesManager {
|
|||||||
async installNodes(list, btn, title, selected_version) {
|
async installNodes(list, btn, title, selected_version) {
|
||||||
let stats = await api.fetchApi('/manager/queue/status');
|
let stats = await api.fetchApi('/manager/queue/status');
|
||||||
stats = await stats.json();
|
stats = await stats.json();
|
||||||
if(stats.in_progress) {
|
if(stats.is_processing) {
|
||||||
customAlert(`[ComfyUI-Manager] There are already tasks in progress. Please try again after it is completed. (${stats.done_count}/${stats.total_count})`);
|
customAlert(`[ComfyUI-Manager] There are already tasks in progress. Please try again after it is completed. (${stats.done_count}/${stats.total_count})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -634,7 +634,7 @@ export class ModelManager {
|
|||||||
let stats = await api.fetchApi('/manager/queue/status');
|
let stats = await api.fetchApi('/manager/queue/status');
|
||||||
|
|
||||||
stats = await stats.json();
|
stats = await stats.json();
|
||||||
if(stats.in_progress) {
|
if(stats.is_processing) {
|
||||||
customAlert(`[ComfyUI-Manager] There are already tasks in progress. Please try again after it is completed. (${stats.done_count}/${stats.total_count})`);
|
customAlert(`[ComfyUI-Manager] There are already tasks in progress. Please try again after it is completed. (${stats.done_count}/${stats.total_count})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "comfyui-manager"
|
name = "comfyui-manager"
|
||||||
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
|
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
|
||||||
version = "3.13"
|
version = "3.13.1"
|
||||||
license = { file = "LICENSE.txt" }
|
license = { file = "LICENSE.txt" }
|
||||||
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]
|
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user