def runonce(exc_class=Exception):
 def runonce_meth(meth):
  @wraps(meth)
  def inner_runonce_meth(self, *args):
   if (not getattr(self, '_already_executed', False)):
    self._already_executed = True
    return meth(self, *args)
   raise exc_class()
  return inner_runonce_meth
 return runonce_meth

def runonce ( exc_class = Exception ) : def runonce_meth ( meth ) : @ wraps ( meth ) def inner_runonce_meth ( self , * args ) : if ( not getattr ( self , '_already_executed' , False ) ) : self . _already_executed = True return meth ( self , * args ) raise exc_class ( ) return inner_runonce_meth return runonce_meth
function to decorate methods that should be called only once .