Are variables reset at 0.00 hr?

Hi all, i have a workflow trigger by a timer. Next a python code that increment a global variable by 1 in an execution and reset that variable if >20, after that put the value of the variable in a custom request to send out. I notice that if i set the timer trigger often ex. 1 hour , the workflow works correctly and when triggered the variable assume all the value from 1 to 20( often jump the value 20 but i’not sure why).
But if i set the trigger to start 2 times a day ( as i wish) , that variable value output is 1 or 2 and then reset to 1.
So maybe the variable are reset because the 0.00 hr? there is a way to avoid it ?

Hope i explain correctly. Thank for any help.

Hi @fedbusup , could you share your code here?

g = 0
def handler(pd: “pipedream”):
global g
if g<21: g = g + 1
else: g = 1
return g

Thank you. Global variables won’t work in this way. The variable will persist on a single execution environment, but those will periodically be destroyed and replaced with a new environment. The same goes for files that you store to /tmp: you can’t rely on files remaining for longer than a single execution.

I’d recommend using a data store, which will let you store and retrieve data across any execution. You can also store data in one workflow and retrieve it in another.

thanks a lot. But shouldn’t work with any time trigger , instead with a short time works correctly. I guess ii’ll go with your solution and try. thanks

Yes, the environment may stick around for a few executions, and that’s likely what you’re seeing. But the issue is that you can’t rely on it. A single environment may stay alive for a single execution or ten, but eventually it will die, so you’ll want to persist the data somewhere outside of the environment.