Skip to content

Instantly share code, notes, and snippets.

@EnigmaCurry
Created March 3, 2011 18:27
Show Gist options
  • Save EnigmaCurry/853227 to your computer and use it in GitHub Desktop.
Save EnigmaCurry/853227 to your computer and use it in GitHub Desktop.
@jessenoller lunch break challenge : http://twitter.com/#!/jessenoller/status/43371023306981376
from threading import Timer
class SuicidalKey(object):
"""
>>> k = SuicidalKey("asdf",30)
>>> k.key
'asdf'
>>> # Before 30 seconds are up
>>> k.reset_expiration(30)
>>> # Wait 30 seconds
>>> k.key
None
"""
def __init__(self, key, expiration_time=300):
self.key = key
self.__expire_timer = Timer(0,None)
self.reset_expiration(expiration_time)
def __expire_key(self):
self.key = None
def reset_expiration(self, expiration_time=300):
if self.key:
self.__expire_timer.cancel()
self.__expire_timer = Timer(expiration_time, self.__expire_key)
self.__expire_timer.start()
@zzzeek
Copy link

zzzeek commented Mar 3, 2011

yup, many methods will fail in this partial example including d.values(). was just to illustrate the method of associating timestamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment