def blockingCallFromThread(reactor, f, *a, **kw):
    "\n    Run a function in the reactor from a thread, and wait for the result\n    synchronously.  If the function returns a L{Deferred}, wait for its\n    result and return that.\n\n    @param reactor: The L{IReactorThreads} provider which will be used to\n        schedule the function call.\n    @param f: the callable to run in the reactor thread\n    @type f: any callable.\n    @param a: the arguments to pass to C{f}.\n    @param kw: the keyword arguments to pass to C{f}.\n\n    @return: the result of the L{Deferred} returned by C{f}, or the result\n        of C{f} if it returns anything other than a L{Deferred}.\n\n    @raise: If C{f} raises a synchronous exception,\n        C{blockingCallFromThread} will raise that exception.  If C{f}\n        returns a L{Deferred} which fires with a L{Failure},\n        C{blockingCallFromThread} will raise that failure's exception (see\n        L{Failure.raiseException}).\n    "
    queue = Queue.Queue()

    def _callFromThread():
        result = defer.maybeDeferred(f, *a, **kw)
        result.addBoth(queue.put)
    reactor.callFromThread(_callFromThread)
    result = queue.get()
    if isinstance(result, failure.Failure):
        result.raiseException()
    return result
Run a function in the reactor from a thread, and wait for the result
synchronously.  If the function returns a L{Deferred}, wait for its
result and return that.

@param reactor: The L{IReactorThreads} provider which will be used to
    schedule the function call.
@param f: the callable to run in the reactor thread
@type f: any callable.
@param a: the arguments to pass to C{f}.
@param kw: the keyword arguments to pass to C{f}.

@return: the result of the L{Deferred} returned by C{f}, or the result
    of C{f} if it returns anything other than a L{Deferred}.

@raise: If C{f} raises a synchronous exception,
    C{blockingCallFromThread} will raise that exception.  If C{f}
    returns a L{Deferred} which fires with a L{Failure},
    C{blockingCallFromThread} will raise that failure's exception (see
    L{Failure.raiseException}).
def blockingCallFromThread(reactor, f, *a, **kw):
    "\n    Run a function in the reactor from a thread, and wait for the result\n    synchronously.  If the function returns a L{Deferred}, wait for its\n    result and return that.\n\n    @param reactor: The L{IReactorThreads} provider which will be used to\n        schedule the function call.\n    @param f: the callable to run in the reactor thread\n    @type f: any callable.\n    @param a: the arguments to pass to C{f}.\n    @param kw: the keyword arguments to pass to C{f}.\n\n    @return: the result of the L{Deferred} returned by C{f}, or the result\n        of C{f} if it returns anything other than a L{Deferred}.\n\n    @raise: If C{f} raises a synchronous exception,\n        C{blockingCallFromThread} will raise that exception.  If C{f}\n        returns a L{Deferred} which fires with a L{Failure},\n        C{blockingCallFromThread} will raise that failure's exception (see\n        L{Failure.raiseException}).\n    "
    queue = Queue.Queue()

    def _callFromThread():
        result = defer.maybeDeferred(f, *a, **kw)
        result.addBoth(queue.put)
    reactor.callFromThread(_callFromThread)
    result = queue.get()
    if isinstance(result, failure.Failure):
        result.raiseException()
    return result