def run_on_executor(*args, **kwargs):
 def run_on_executor_decorator(fn):
  executor = kwargs.get('executor', 'executor')
  io_loop = kwargs.get('io_loop', 'io_loop')
  @functools.wraps(fn)
  def wrapper(self, *args, **kwargs):
   callback = kwargs.pop('callback', None)
   future = getattr(self, executor).submit(fn, self, *args, **kwargs)
   if callback:
    getattr(self, io_loop).add_future(future, (lambda future: callback(future.result())))
   return future
  return wrapper
 if (args and kwargs):
  raise ValueError('cannot combine positional and keyword args')
 if (len(args) == 1):
  return run_on_executor_decorator(args[0])
 elif (len(args) != 0):
  raise ValueError('expected 1 argument, got %d', len(args))
 return run_on_executor_decorator

def run_on_executor ( * args , ** kwargs ) : def run_on_executor_decorator ( fn ) : executor = kwargs . get ( 'executor' , 'executor' ) io_loop = kwargs . get ( 'io_loop' , 'io_loop' ) @ functools . wraps ( fn ) def wrapper ( self , * args , ** kwargs ) : callback = kwargs . pop ( 'callback' , None ) future = getattr ( self , executor ) . submit ( fn , self , * args , ** kwargs ) if callback : getattr ( self , io_loop ) . add_future ( future , ( lambda future : callback ( future . result ( ) ) ) ) return future return wrapper if ( args and kwargs ) : raise ValueError ( 'cannot combine positional and keyword args' ) if ( len ( args ) == 1 ) : return run_on_executor_decorator ( args [ 0 ] ) elif ( len ( args ) != 0 ) : raise ValueError ( 'expected 1 argument, got %d' , len ( args ) ) return run_on_executor_decorator
decorator to run a synchronous method asynchronously on an executor .