Automatically expiring variable

后端 未结 6 2057
栀梦
栀梦 2021-01-13 08:21

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

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 09:06

    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.)

提交回复
热议问题