# Can I disable an interval if there is an error

**URL:** <https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851>\
**Category:** Dash Python\
**Created:** [March 4, 2025, 9:43pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851 "2025-03-04T21:43:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![voidtrance](https://avatars.discourse-cdn.com/v4/letter/v/b77776/32.png) [@voidtrance](https://community.plotly.com/u/voidtrance)\
**Post date:** [March 4, 2025, 9:43pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/1 "2025-03-04T21:43:52Z")

</div>

I am using `dcc.Interval` to dynamically update graph. This, correctly, causes the webpage to reload periodically and display new data.

What I want to accomplish is that the periodic reload of the webpage gets automatically disabled if there is an error. Normally, it just keeps reloading even if Python app is terminated.

---

<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:** [March 5, 2025, 6:55am UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/2 "2025-03-05T06:55:40Z")

</div>

Hey @voidtrance.

Iḿ not sure how to do that. What would be the use case? I mean if there is an error and the app stopped working why would you keep the browser open?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [March 5, 2025, 2:41pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/3 "2025-03-05T14:41:14Z")

</div>

Hello @voidtrance,

Yse, you can use the `on_error` for the callback to `set_props` on the interval to a different value, or stop it entirely.

This is very flexible to what you want to do. 🙂 You can even have the entire app alert you when there are errors. 😃

---

<div class="post-metadata">

**Author:** ![voidtrance](https://avatars.discourse-cdn.com/v4/letter/v/b77776/32.png) [@voidtrance](https://community.plotly.com/u/voidtrance)\
**Post date:** [March 5, 2025, 2:53pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/4 "2025-03-05T14:53:04Z")

</div>

Thanks, this was very helpful.

I have a follow up question about `dcc.Interval`.

The documentation states that `n_intervals` will be updated every `interval` milliseconds. But it does not talk about how often the callbacks are being called. Is there some documentation that describes the frequency of calling callbacks and how that can be controlled?

---

<div class="post-metadata">

**Author:** ![voidtrance](https://avatars.discourse-cdn.com/v4/letter/v/b77776/32.png) [@voidtrance](https://community.plotly.com/u/voidtrance)\
**Post date:** [March 5, 2025, 3:04pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/5 "2025-03-05T15:04:03Z")

</div>

I would like to come back to the `on_error` situation.

I also want the webpage to stop continuously reloading. Is there a way to make that happen?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [March 5, 2025, 5:30pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/6 "2025-03-05T17:30:33Z")

</div>

> [@voidtrance](#):
>
> The documentation states that `n_intervals` will be updated every `interval` milliseconds. But it does not talk about how often the callbacks are being called. Is there some documentation that describes the frequency of calling callbacks and how that can be controlled?

Yes, you can check out here: [Interval | Dash for Python Documentation | Plotly](https://dash.plotly.com/dash-core-components/interval)

Should be `interval`. Default is `1000` or `1` second.

> [@voidtrance](#):
>
> I would like to come back to the `on_error` situation.
> 
> I also want the webpage to stop continuously reloading. Is there a way to make that happen?

Not sure what you mean on this one.

You could disable debug mode to keep from hot\_reloading. If the app is encountering an error, this is the default process to reload the failed state.

---

<div class="post-metadata">

**Author:** ![voidtrance](https://avatars.discourse-cdn.com/v4/letter/v/b77776/32.png) [@voidtrance](https://community.plotly.com/u/voidtrance)\
**Post date:** [March 5, 2025, 6:18pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/7 "2025-03-05T18:18:53Z")

</div>

> [@jinnyzor](#):
>
> Yes, you can check out here: [Interval | Dash for Python Documentation | Plotly](https://dash.plotly.com/dash-core-components/interval)
> 
> Should be `interval`. Default is `1000` or `1` second.

Hmm, I have an interval set to `50` milliseconds. I also added a `print()` statement in my callback and while I generally see time differences of about 0.05 seconds between calls, there are also some huge gaps.

Here is how my app is setup:

```python
...
    app.layout = html.Div([
        html.Div([
            html.Button('Stop Refresh', id='refresh-control', n_clicks=0)
        ], title="Refresh Control"),
        html.Div([
            dcc.Graph(id="travel-plot", figure=fig),
            dcc.Interval(id="interval-component", interval=50, n_intervals=0)
        ]),
        html.Div([
            dcc.Graph(id="heater-temps", figure=tfig),
            dcc.Interval(id="temp-interval-component", interval=1000, n_intervals=0)
        ])
    ])

    start_time = time.time()

    @app.callback(Output('travel-plot', 'extendData'),
                  Input('interval-component', 'n_intervals'))
    def update_path_data(n):
        print(time.time())
        pos, temps = get_data(connection, toolhead, *heaters)
        data = {'x':[[pos[0]]], 'y': [[pos[1]]], 'z': [[pos[2]]]}
        return data
...

```

And here is the output that I get:

```auto
1741198379.4000185
1741198379.4341614
1741198379.5649786
1741198379.585141
1741198379.642623
1741198379.697914
1741198379.8117445
1741198384.5249014

```

In the last call, the gap was 5 seconds.

I also want to be able to call the callback with a higher frequency but I found that any `interval` value of less than 50 results in the scatter plot now showing at all.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [March 5, 2025, 6:23pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/8 "2025-03-05T18:23:44Z")

</div>

The further you get away from the source, the longer the time between the calls will be.

---

<div class="post-metadata">

**Author:** ![voidtrance](https://avatars.discourse-cdn.com/v4/letter/v/b77776/32.png) [@voidtrance](https://community.plotly.com/u/voidtrance)\
**Post date:** [March 5, 2025, 7:12pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/9 "2025-03-05T19:12:10Z")

</div>

I am not sure what you mean by that. The app and the browser are running on the same system. There should be hardly any latency in getting the response.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [March 5, 2025, 7:25pm UTC](https://community.plotly.com/t/can-i-disable-an-interval-if-there-is-an-error/90851/10 "2025-03-05T19:25:51Z")

</div>

The latency, if you were to host it, you should keep in mind.

By default, dash / flask is a sync environment, meaning completion time will block other aspects of the code. You can get around this when you host, but its still in a blocking nature.

Then you also have the rendering on the clientside for the data.

Anyways, requests will keep piling up from the browser to the server since it is not async.

As far as stopping an `interval`:

![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/0/8/08096129914a1caeb2da321f4a30f13f42cff08a.png)
