Automatically expiring variable

后端 未结 6 2058
栀梦
栀梦 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 08:48

    import sched
    import time
    import threading
    
    a = [1, 2, 3, 4, 5, 6]
    
    scheduler = sched.scheduler(time.time, time.sleep)
    
    def delete(_list):
        del _list[0]
    
    for i in range(len(a)):
        scheduler.enter(60*10*i, 1, delete, (a,))
    
    t = threading.Thread(target=scheduler.run)
    
    t.start()
    

提交回复
热议问题