1

I am runnning a code and saving entries in a dictionary. HOw can I hold on to this dictionary for 1 min, after which I want to delete its entries, except for those that are 10 sec old?

I am running a certain function in a loop, and I want to save some data generated in that function for analysis in another function later on.

Time calculation: How can I measure one min ?

There's the following, Measure time elapsed in Python? But that I think wont work with the following code structure.

import time 
dict={}
def function_run_in_main():
   global dict
   dict[key]=value
   # check time here and delete
Community
  • 1
  • 1
Fatima
  • 1,611
  • 6
  • 18
  • 21
  • 2
    Possibly overkill - but you may wish to consider redis or memcache – Jon Clements Oct 11 '13 at 01:36
  • 3
    You need to add way more detail in your post about the specific nature of your problem. Why do you want make entries expire after some time? How are you calculating time? Is your code running in a loop of sorts or do you need another thread to monitor the `dict`/ – inspectorG4dget Oct 11 '13 at 01:37

0 Answers0