Skip to content

Commit 464ba1d

Browse files
authored
Accept prompt_id in interrupt handler (#9607)
* Accept prompt_id in interrupt handler * remove a log
1 parent e3018c2 commit 464ba1d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

server.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,34 @@ async def post_queue(request):
729729

730730
@routes.post("/interrupt")
731731
async def post_interrupt(request):
732-
nodes.interrupt_processing()
732+
try:
733+
json_data = await request.json()
734+
except json.JSONDecodeError:
735+
json_data = {}
736+
737+
# Check if a specific prompt_id was provided for targeted interruption
738+
prompt_id = json_data.get('prompt_id')
739+
if prompt_id:
740+
currently_running, _ = self.prompt_queue.get_current_queue()
741+
742+
# Check if the prompt_id matches any currently running prompt
743+
should_interrupt = False
744+
for item in currently_running:
745+
# item structure: (number, prompt_id, prompt, extra_data, outputs_to_execute)
746+
if item[1] == prompt_id:
747+
logging.info(f"Interrupting prompt {prompt_id}")
748+
should_interrupt = True
749+
break
750+
751+
if should_interrupt:
752+
nodes.interrupt_processing()
753+
else:
754+
logging.info(f"Prompt {prompt_id} is not currently running, skipping interrupt")
755+
else:
756+
# No prompt_id provided, do a global interrupt
757+
logging.info("Global interrupt (no prompt_id specified)")
758+
nodes.interrupt_processing()
759+
733760
return web.Response(status=200)
734761

735762
@routes.post("/free")

0 commit comments

Comments
 (0)