def deferToThreadPool(reactor, threadpool, f, *args, **kwargs):
 d = defer.Deferred()
 def onResult(success, result):
  if success:
   reactor.callFromThread(d.callback, result)
  else:
   reactor.callFromThread(d.errback, result)
 threadpool.callInThreadWithCallback(onResult, f, *args, **kwargs)
 return d

def deferToThreadPool ( reactor , threadpool , f , * args , ** kwargs ) : d = defer . Deferred ( ) def onResult ( success , result ) : if success : reactor . callFromThread ( d . callback , result ) else : reactor . callFromThread ( d . errback , result ) threadpool . callInThreadWithCallback ( onResult , f , * args , ** kwargs ) return d
call the function c{f} using a thread from the given threadpool and return the result as a deferred .