def run_in_executor(f):
 @wraps(f)
 def new_f(self, *args, **kwargs):
  if self.is_shutdown:
   return
  try:
   future = self.executor.submit(f, self, *args, **kwargs)
   future.add_done_callback(_future_completed)
  except Exception:
   log.exception('Failed to submit task to executor')
 return new_f

def run_in_executor ( f ) : @ wraps ( f ) def new_f ( self , * args , ** kwargs ) : if self . is_shutdown : return try : future = self . executor . submit ( f , self , * args , ** kwargs ) future . add_done_callback ( _future_completed ) except Exception : log . exception ( 'Failed to submit task to executor' ) return new_f
a decorator to run the given method in the threadpoolexecutor .