Should I use an Interval for a one-off delay?

To “destroy” the timer you can just set a callback to update the ‘interval’ property to a really large number.

This is a useful idea. My dilemma is what should trigger said callback. At the moment, in my code, it naturally would be triggered by the timer! I.e. I want the timer to count a certain number of intervals and then stop itself. Which creates a loop (either of the not-allowed kind or of the sneakily-allowed-but-self-triggering kind). If I trigger the timer turnoff from the UI component that got updated by the timer, I again have a loop, just a slightly longer one.

Edit: I’ve just understood that this probably isn’t a loop - I can trigger on n_intervals and update interval, so long as changing interval doesn’t cause n_intervals to automatically reset or anything. This is probably a good solution! But I’ll leave the rest of my post below just in case it’s of interest.


When I put it this way, the cleanest solution to my problem would be if dcc.Interval() supported the idea of counting a certain number of ticks and then stopping by itself, i.e. had something like a max_intervals parameter. I’m not sure if you have any other use-cases for that but if so, maybe it’s a feature suggestion?

The really clean solution my problem would be if a callback could say “do A, wait 2 seconds, then do B”, but that is totally contrary to structure of the framework I think.

1 Like