def check_interaction(fn):
 def check_fn(self, *args, **kwargs):
  interact_lock.acquire()
  try:
   if self.filename:
    self.clear_interaction()
    return fn(self, *args, **kwargs)
  finally:
   interact_lock.release()
 return check_fn

def check_interaction ( fn ) : def check_fn ( self , * args , ** kwargs ) : interact_lock . acquire ( ) try : if self . filename : self . clear_interaction ( ) return fn ( self , * args , ** kwargs ) finally : interact_lock . release ( ) return check_fn
decorator to clean and prevent interaction when not available .