>>> import time >>> oldtime = 0 >>> def myfunc(): ... mt = time.time() ... ot = globals()['oldtime'] ... if mt >= ot + 5: ... print "Execute the code" ... else: ... print "You called me too soon!" ... globals()['oldtime'] = mt ... >>> myfunc() Execute the code >>> print "I'm waiting for a while..." I'm waiting for a while... >>> myfunc() Execute the code >>> myfunc() You called me too soon! >>>