def _log_and_ignore_exceptions(f):
 def wrapped(self, *args, **dargs):
  try:
   return f(self, *args, **dargs)
  except Exception as e:
   print ('LogfileMonitor.%s failed with exception %s' % (f.__name__, e))
   print 'Exception ignored:'
   traceback.print_exc(file=sys.stdout)
 wrapped.__name__ = f.__name__
 wrapped.__doc__ = f.__doc__
 wrapped.__dict__.update(f.__dict__)
 return wrapped

def _log_and_ignore_exceptions ( f ) : def wrapped ( self , * args , ** dargs ) : try : return f ( self , * args , ** dargs ) except Exception as e : print ( 'LogfileMonitor.%s failed with exception %s' % ( f . __name__ , e ) ) print 'Exception ignored:' traceback . print_exc ( file = sys . stdout ) wrapped . __name__ = f . __name__ wrapped . __doc__ = f . __doc__ wrapped . __dict__ . update ( f . __dict__ ) return wrapped
decorator: automatically log exception during a method call .