def callInThreadWithCallback(self, onResult, function, *args, **kwargs):

    def _(res):
        if isinstance(res, Failure):
            onResult(False, res)
        else:
            onResult(True, res)
    d = Deferred()
    d.addCallback((lambda x: function(*args, **kwargs)))
    d.addBoth(_)
    clock._reactor.callLater(0, d.callback, True)
    return d
def callInThreadWithCallback(self, onResult, function, *args, **kwargs):

    def _(res):
        if isinstance(res, Failure):
            onResult(False, res)
        else:
            onResult(True, res)
    d = Deferred()
    d.addCallback((lambda x: function(*args, **kwargs)))
    d.addBoth(_)
    clock._reactor.callLater(0, d.callback, True)
    return d