How to implement an automatically expiring variable in python? For example, Let the program running For one hour. I want implement an array of 6 variables, each variable in
Hmmm, seems weird, but possible.
Sounds like you need a class which records the time when __init__
is called. Then, implement __getitem__
to check the time when it is called, and only return the item if it's not too late. (It's probably easier to do this than to have a process "running in the background" which actively deletes items even when you don't ask for them.)