I’m running a subprocess with its stdout piped, reading it using an interval timer, and displaying the output. I’d like to turn off the timer when the subprocess completes.
I tried creating a callback with Output(interval_id, ‘interval’) that detects if the subprocess has exited, and returns a value to reset the interval timer to something that effectively turns it off. I’ve tried values of 0, -1, and None but the timer keeps on ticking. How do I disable it? Do I have to remove it from the Div?
I tried setting the timer to an insanely large number but that doesn’t seem to work either so I don’t have much advice to give you in the meantime until we get that addition merged and released.
I am simply setting the interval to 60*60*1000 for an 1 hour interval when output ends, and when output end is not found, I am returning the default interval value. That works fine.
This should work and it looks like @radekwlsk was able to make this work with 1 hour. From SO, it looks like the maximum value for interval is 2,147,483,647 (2^31-1)) so perhaps this was being set to a number larger than that.
I’m not sure what you mean by “subprocess” or “process running in the background”. Interval doesn’t start a new process, it just fires your callbacks. In either case, the solution that you provided looks good. You could also even just update the interval property of the interval-component if it was displayed in the app.layout.
This was fixed a few months ago and has been available in dash-core-components since version 0.43.0. You can now write a callback that targets the disabled prop of your Interval.
Note - As per the dcc.Interval documentation, there are two properties that can be used to turn off dcc.Interval: disabled ( boolean ; optional): If True, the counter will no longer update
max_intervals ( number ; default -1 ): Number of times the interval will be fired. If -1, then the interval has no limit (the default) and if 0 then the interval stops running.