# Interrupt execution of queued callbacks

**URL:** <https://community.plotly.com/t/interrupt-execution-of-queued-callbacks/76476>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [June 28, 2023, 8:46am UTC](https://community.plotly.com/t/interrupt-execution-of-queued-callbacks/76476 "2023-06-28T08:46:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![christoph.b](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@christoph.b](https://community.plotly.com/u/christoph.b)\
**Post date:** [June 28, 2023, 8:46am UTC](https://community.plotly.com/t/interrupt-execution-of-queued-callbacks/76476/1 "2023-06-28T08:46:52Z")

</div>

Hi, I have a question about the execution of callbacks.

I have a dash app with a scatter plot and a line plot. When hovering over the markers in the scatter plot, a callback is triggered that updates the line plot. I feel like when I quickly hover over many scatter markers and the callback that updates the line plot is triggered many times, the executions of this callback queue up.  
I would like to interrupt the execution of the callback whenever the same callback is triggered again. This means that, when hovering over many scatter markers, only the callback for the scatter marker that was hovered over most recently is executed and all the previous callbacks that might still be running are interrupted. Is this possible?

I hope that I could make clear what I am trying to achieve.

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [June 28, 2023, 9:38am UTC](https://community.plotly.com/t/interrupt-execution-of-queued-callbacks/76476/2 "2023-06-28T09:38:19Z")

</div>

HI @christoph.b

Something like this might work, but I’m not sure if this makes your chart more responsive.

```python
import json
from dash import Dash, DiskcacheManager, dcc, Input, Output, html, callback
import diskcache
import plotly.graph_objects as go
import numpy as np

cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)

app = Dash( __name__ , background_callback_manager=background_callback_manager)

app.layout = html.Div(
    [
        dcc.Graph(
            id='graph',
            figure=go.Figure(
                go.Scatter(
                    x=np.arange(50),
                    y=np.random.randint(0, 1000, 50),
                    mode='markers'
                )
            )
        ),
        html.Pre(id='out')
    ]
)

@callback(
    output=Output("out", "children"),
    inputs=Input("graph", "hoverData"),
    background=True,
    cancel=[Input("graph", "hoverData")],
)
def update_clicks(hoverData):
    return json.dumps(hoverData, indent=2)

if __name__ == " __main__":
    app.run(debug=True)

```

---

<div class="post-metadata">

**Author:** ![winstonchiong](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@winstonchiong](https://community.plotly.com/u/winstonchiong)\
**Post date:** [May 4, 2024, 9:31am UTC](https://community.plotly.com/t/interrupt-execution-of-queued-callbacks/76476/3 "2024-05-04T09:31:40Z")

</div>

Hey @christoph.b!

Were you able to solve this problem? I’m running into the same issue!

I tried using `BlockingCallbackTransform()` from `dash-extensions` but I couldn’t get it to work with pages. Let me know if you have a solution!

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [May 4, 2024, 10:03pm UTC](https://community.plotly.com/t/interrupt-execution-of-queued-callbacks/76476/4 "2024-05-04T22:03:22Z")

</div>

Hey @winstonchiong, just out of curiosity, did you try what I proposed back then?

---

<div class="post-metadata">

**Author:** ![winstonchiong](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@winstonchiong](https://community.plotly.com/u/winstonchiong)\
**Post date:** [May 5, 2024, 1:28am UTC](https://community.plotly.com/t/interrupt-execution-of-queued-callbacks/76476/5 "2024-05-05T01:28:43Z")

</div>

I’ve never really gotten background callbacks to work unfortunately, so I didn’t go that route. Celery is recommended for production but Celery requires some infrastructure.
