mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-26 09:49:26 +08:00
Return interrupted=True/False to caller
This commit is contained in:
parent
039ed38ed1
commit
41234d62b0
63
server.py
63
server.py
@ -994,36 +994,45 @@ class PromptServer():
|
|||||||
return web.Response(status=200)
|
return web.Response(status=200)
|
||||||
|
|
||||||
@routes.post("/interrupt")
|
@routes.post("/interrupt")
|
||||||
async def post_interrupt(request):
|
async def post_interrupt(request):
|
||||||
try:
|
try:
|
||||||
json_data = await request.json()
|
json_data = await request.json()
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
json_data = {}
|
json_data = {}
|
||||||
|
|
||||||
# Check if a specific prompt_id was provided for targeted interruption
|
prompt_id = json_data.get('prompt_id')
|
||||||
prompt_id = json_data.get('prompt_id')
|
if prompt_id:
|
||||||
if prompt_id:
|
currently_running, _ = self.prompt_queue.get_current_queue()
|
||||||
currently_running, _ = self.prompt_queue.get_current_queue()
|
should_interrupt = False
|
||||||
|
for item in currently_running:
|
||||||
|
if item[1] == prompt_id:
|
||||||
|
logging.info(f"Interrupting prompt {prompt_id}")
|
||||||
|
should_interrupt = True
|
||||||
|
break
|
||||||
|
|
||||||
# Check if the prompt_id matches any currently running prompt
|
if should_interrupt:
|
||||||
should_interrupt = False
|
nodes.interrupt_processing()
|
||||||
for item in currently_running:
|
else:
|
||||||
# item structure: (number, prompt_id, prompt, extra_data, outputs_to_execute)
|
logging.info(f"Prompt {prompt_id} is not currently running, skipping interrupt")
|
||||||
if item[1] == prompt_id:
|
|
||||||
logging.info(f"Interrupting prompt {prompt_id}")
|
|
||||||
should_interrupt = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if should_interrupt:
|
return web.Response(
|
||||||
nodes.interrupt_processing()
|
status=200,
|
||||||
else:
|
content_type="application/json",
|
||||||
logging.info(f"Prompt {prompt_id} is not currently running, skipping interrupt")
|
text=json.dumps({
|
||||||
else:
|
"interrupted": should_interrupt,
|
||||||
# No prompt_id provided, do a global interrupt
|
"prompt_id": prompt_id,
|
||||||
logging.info("Global interrupt (no prompt_id specified)")
|
})
|
||||||
nodes.interrupt_processing()
|
)
|
||||||
|
else:
|
||||||
return web.Response(status=200)
|
logging.info("Global interrupt (no prompt_id specified)")
|
||||||
|
nodes.interrupt_processing()
|
||||||
|
return web.Response(
|
||||||
|
status=200,
|
||||||
|
content_type="application/json",
|
||||||
|
text=json.dumps({
|
||||||
|
"interrupted": True,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
@routes.post("/free")
|
@routes.post("/free")
|
||||||
async def post_free(request):
|
async def post_free(request):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user