Stop scripts from running when page is closed

I have a startup script which I want it to run every 5 min. However, whenever I leave the page (close browser or directly closing the page) and navigating to another page (pervious page is not open anymore) the script is still present in the 'Running Scripts' section. Every time I go back to the page another script is added on the section and now multiple scripts are running.

I am so far using custom property and combining a for loop with time.sleep() to navigate to another page and back. This will close the script after the for loop ends but a constant refresh every 5 min wouldn't be ideal.

Is there a way, I can set it so that my script runs every 5 min as long as the user is on the page and will stops when the user leaves the page.

This is a memory leak, and you are definitely doing something wrong.

This is bad. Ignition and sleep just really don't work together.

Also, I think you are mixing terminology. You are saying Page, but I think what you really mean is View?

Create a custom property on the view. Use an expression binding with this expression getMinute(now(1000))

Then in the propertyChange event script for that property use this script:

if not currentValue.value % 5:
    #run script

Add a custom property to your view.
Make it an expression binding with this expression: now(300000)
Put your script in the value change script of that property.

2 Likes

Use a docked view with your page. Add a custom property to the view and use an expression binding like so:

runScript("path.to.script.function", 300000)

Place the script in a function in your project library.

3 Likes

Yes, that makes more sense than an on change script... Sometimes I think things only halfway through...