def _threaded_method(method_name, sync_name, reactor_name, threadpool_name):
 def _run_in_thread(self, *args, **kwargs):
  reactor = getattr(self, reactor_name)
  sync = getattr(self, sync_name)
  threadpool = getattr(self, threadpool_name)
  original = getattr(sync, method_name)
  return deferToThreadPool(reactor, threadpool, preserve_context(original), *args, **kwargs)
 return _run_in_thread

def _threaded_method ( method_name , sync_name , reactor_name , threadpool_name ) : def _run_in_thread ( self , * args , ** kwargs ) : reactor = getattr ( self , reactor_name ) sync = getattr ( self , sync_name ) threadpool = getattr ( self , threadpool_name ) original = getattr ( sync , method_name ) return deferToThreadPool ( reactor , threadpool , preserve_context ( original ) , * args , ** kwargs ) return _run_in_thread
create a method that calls another method in a threadpool .