Gradio cancel a running process

Is there a way to cancel a running process if it is taking too long to complete? Iโ€™ve looked at the cancels for a button.click(). Which is being discussed here Is there a way to kill a function in mid proccess? - Gradio - Hugging Face Forums But I donโ€™t seem to be able to get it to work.

My button click event looks like the following:

send_chat = txt.submit(update_human_message, [chatbot, txt, memory], [chatbot, txt, memory])
btn.click(fn=None, inputs=None, outputs=None, cancels=[send_chat], queue=False)

#calling the gradio app
demo.queue(concurrency_count=2, max_size=20).launch()

Could someone please guide me?

Hi @bhashithe what happens when you click on the button? Does the process get canceled in the frontend?

Hi @abidlabs
Nothing really happens on the frontend, but i can see that the reset and predict responses.

reset has a response {"success":true}
predict has a response {"data":[],"is_generating":false,"duration":0.0,"average_duration":0.0}

The textbox shows still running even after clicking the button which triggers the cancel event. After a while we get the response for the query which was initially sent (even though this was cancelled)

Can you provide a self-contained code example we can use to reproduce?