'A synchronous version of L{deferToThread}.
@param f: The callable to invoke.
@type f: L{callable}
@param args: Positional arguments to the callable.
@param kwargs: Keyword arguments to the callable.
@return: A L{Deferred} that fires with the result of applying
C{f} to C{args} and C{kwargs} or the exception raised.'

def synchronousDeferredToThread(self, f, *args, **kwargs):

    try:
        result = f(*args, **kwargs)
    except:
        return defer.fail()
    else:
        return defer.succeed(result)
