PERF 去除多余的运行完成后重启ComfyUI操作

This commit is contained in:
kyj@bowong.ai 2025-05-19 18:38:56 +08:00
parent cd8f44f9b4
commit 2d9e351f4c
3 changed files with 54 additions and 75 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
.pypirc
.env
.idea
.idea
test*

View File

@ -526,45 +526,34 @@ with comfyui_image.imports():
cleanup_span.set_tag("success", "false")
cleanup_successful = False
logger.info("清理资源并重启ComfyUI")
restart_successful = True # 跟踪重启是否成功的标志
with sentry_sdk.start_span(op="system.restart", description="重启ComfyUI") as restart_span:
try:
# 停止ComfyUI
with sentry_sdk.start_span(op="system.stop", description="停止ComfyUI") as stop_span:
cmd = "comfy stop"
subprocess.run(cmd, shell=True, check=True)
time.sleep(1)
stop_span.set_tag("success", "true")
# 设置状态为成功
stop_span.set_status("ok")
except Exception as stop_error:
logger.error(f"停止ComfyUI失败: {stop_error}")
restart_span.set_data("stop_error", str(stop_error))
restart_span.set_tag("stop_success", "false")
# 设置状态为错误
restart_span.set_status("internal_error")
restart_successful = False
try:
# 重启ComfyUI
with sentry_sdk.start_span(op="system.start", description="启动ComfyUI") as start_span:
cmd = "comfy launch --background"
subprocess.run(cmd, shell=True, check=True)
start_span.set_tag("success", "true")
# 设置状态为成功
start_span.set_status("ok")
except Exception as start_error:
logger.error(f"启动ComfyUI失败: {start_error}")
restart_span.set_data("start_error", str(start_error))
restart_span.set_tag("start_success", "false")
# 设置状态为错误
restart_span.set_status("internal_error")
restart_successful = False
modal.experimental.stop_fetching_inputs()
# logger.info("清理资源并重启ComfyUI")
# with sentry_sdk.start_span(op="system.restart", description="重启ComfyUI") as restart_span:
# try:
# # 停止ComfyUI
# with sentry_sdk.start_span(op="system.stop", description="停止ComfyUI") as stop_span:
# cmd = "comfy stop"
# subprocess.run(cmd, shell=True, check=True)
# time.sleep(1)
# stop_span.set_tag("success", "true")
# except Exception as stop_error:
# logger.error(f"停止ComfyUI失败: {stop_error}")
# restart_span.set_data("stop_error", str(stop_error))
# restart_span.set_tag("stop_success", "false")
#
# try:
# # 重启ComfyUI
# with sentry_sdk.start_span(op="system.start", description="启动ComfyUI") as start_span:
# cmd = "comfy launch --background"
# subprocess.run(cmd, shell=True, check=True)
# start_span.set_tag("success", "true")
# except Exception as start_error:
# logger.error(f"启动ComfyUI失败: {start_error}")
# restart_span.set_data("start_error", str(start_error))
# restart_span.set_tag("start_success", "false")
# modal.experimental.stop_fetching_inputs()
# 根据清理和重启结果设置总体清理状态
if cleanup_successful and restart_successful:
if cleanup_successful:
cleanup_span.set_status("ok")
else:
cleanup_span.set_status("internal_error")

View File

@ -495,45 +495,34 @@ with comfyui_latentsync_1_5_image.imports():
cleanup_span.set_tag("success", "false")
cleanup_successful = False
logger.info("清理资源并重启ComfyUI")
restart_successful = True # 跟踪重启是否成功的标志
with sentry_sdk.start_span(op="system.restart", description="重启ComfyUI") as restart_span:
try:
# 停止ComfyUI
with sentry_sdk.start_span(op="system.stop", description="停止ComfyUI") as stop_span:
cmd = "comfy stop"
subprocess.run(cmd, shell=True, check=True)
time.sleep(1)
stop_span.set_tag("success", "true")
# 设置状态为成功
stop_span.set_status("ok")
except Exception as stop_error:
logger.error(f"停止ComfyUI失败: {stop_error}")
restart_span.set_data("stop_error", str(stop_error))
restart_span.set_tag("stop_success", "false")
# 设置状态为错误
restart_span.set_status("internal_error")
restart_successful = False
try:
# 重启ComfyUI
with sentry_sdk.start_span(op="system.start", description="启动ComfyUI") as start_span:
cmd = "comfy launch --background"
subprocess.run(cmd, shell=True, check=True)
start_span.set_tag("success", "true")
# 设置状态为成功
start_span.set_status("ok")
except Exception as start_error:
logger.error(f"启动ComfyUI失败: {start_error}")
restart_span.set_data("start_error", str(start_error))
restart_span.set_tag("start_success", "false")
# 设置状态为错误
restart_span.set_status("internal_error")
restart_successful = False
modal.experimental.stop_fetching_inputs()
# logger.info("清理资源并重启ComfyUI")
# with sentry_sdk.start_span(op="system.restart", description="重启ComfyUI") as restart_span:
# try:
# # 停止ComfyUI
# with sentry_sdk.start_span(op="system.stop", description="停止ComfyUI") as stop_span:
# cmd = "comfy stop"
# subprocess.run(cmd, shell=True, check=True)
# time.sleep(1)
# stop_span.set_tag("success", "true")
# except Exception as stop_error:
# logger.error(f"停止ComfyUI失败: {stop_error}")
# restart_span.set_data("stop_error", str(stop_error))
# restart_span.set_tag("stop_success", "false")
#
# try:
# # 重启ComfyUI
# with sentry_sdk.start_span(op="system.start", description="启动ComfyUI") as start_span:
# cmd = "comfy launch --background"
# subprocess.run(cmd, shell=True, check=True)
# start_span.set_tag("success", "true")
# except Exception as start_error:
# logger.error(f"启动ComfyUI失败: {start_error}")
# restart_span.set_data("start_error", str(start_error))
# restart_span.set_tag("start_success", "false")
# modal.experimental.stop_fetching_inputs()
# 根据清理和重启结果设置总体清理状态
if cleanup_successful and restart_successful:
if cleanup_successful:
cleanup_span.set_status("ok")
else:
cleanup_span.set_status("internal_error")