# Gradio cancel a running process

**URL:** <https://discuss.huggingface.co/t/gradio-cancel-a-running-process/50466>\
**Category:** 🔒 Gradio\
**Created:** [August 11, 2023, 7:15pm UTC](https://discuss.huggingface.co/t/gradio-cancel-a-running-process/50466 "2023-08-11T19:15:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhashithe](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bhashithe](https://discuss.huggingface.co/u/bhashithe)\
**Post date:** [August 11, 2023, 7:15pm UTC](https://discuss.huggingface.co/t/gradio-cancel-a-running-process/50466/1 "2023-08-11T19:15:36Z")

</div>

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](https://discuss.huggingface.co/t/is-there-a-way-to-kill-a-function-in-mid-proccess/25708) But I don’t seem to be able to get it to work.

My button click event looks like the following:

```auto
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?

---

<div class="post-metadata">

**Author:** ![abidlabs](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/abidlabs/32/21878_2.png) [@abidlabs](https://discuss.huggingface.co/u/abidlabs)\
**Post date:** [August 15, 2023, 3:24pm UTC](https://discuss.huggingface.co/t/gradio-cancel-a-running-process/50466/2 "2023-08-15T15:24:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bhashithe](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bhashithe](https://discuss.huggingface.co/u/bhashithe)\
**Post date:** [August 15, 2023, 3:55pm UTC](https://discuss.huggingface.co/t/gradio-cancel-a-running-process/50466/3 "2023-08-15T15:55:59Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![abidlabs](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/abidlabs/32/21878_2.png) [@abidlabs](https://discuss.huggingface.co/u/abidlabs)\
**Post date:** [August 15, 2023, 4:08pm UTC](https://discuss.huggingface.co/t/gradio-cancel-a-running-process/50466/4 "2023-08-15T16:08:33Z")

</div>

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