user_id = 2

def error(request, failure):
    return 'error'

def parse(request):
    def _response(r):
        request.response = r
    def _error(f):
        r = error(request, f)
        request.response = r
    d = transact.Parse(user_id, request.POST['command'])
    d.addCallback(_response)
    d.addErrback(_error)

    def _wait():
        if not(d.called):
            return threading.Timer(0.1, lambda: None)
    t = _wait()
    while(isinstance(t, threading.Timer)):
        t.start()
        t.join()
        t = _wait()
    return request.response

twisted_django.py hosted by GitHub