Skip to content

Instantly share code, notes, and snippets.

@philchristensen
Created July 10, 2011 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philchristensen/1074924 to your computer and use it in GitHub Desktop.
Save philchristensen/1074924 to your computer and use it in GitHub Desktop.
bad idea for calling Twisted code from Django view
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