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

1
.gitignore vendored
View File

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

View File

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