code: def run_on_executor(*args, **kwargs):
      """Decorator to run a synchronous method asynchronously on an executor.
  
      The decorated method may be called with a ``callback`` keyword
      argument and returns a future.
  
      The `.IOLoop` and executor to be used are determined by the ``io_loop``
      and ``executor`` attributes of ``self``. To use different attributes,
      pass keyword arguments to the decorator::
  
          @run_on_executor(executor='_thread_pool')
          def foo(self):
              pass
  
      .. versionchanged:: 4.2
         Added keyword arguments to use alternative attributes.
      """
  
      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
  
imports: from __future__ import absolute_import, division, print_function
  import functools
  import platform
  import textwrap
  import traceback
  import sys
  from tornado.log import app_log
  from tornado.stack_context import ExceptionStackContext, wrap
  from tornado.util import raise_exc_info, ArgReplacer, is_finalizing
label_desc: Use image node_id 2 for calling a global function with example usage: run_on_executor() and returns: run_on_executor_decorator, wrapper, run_on_executor_decorator, future