Created
July 10, 2011 20:17
-
-
Save philchristensen/1074924 to your computer and use it in GitHub Desktop.
bad idea for calling Twisted code from Django view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment