Skip to content

Instantly share code, notes, and snippets.

@mrjoes
Created January 22, 2012 16:30
Show Gist options
  • Save mrjoes/1657598 to your computer and use it in GitHub Desktop.
Save mrjoes/1657598 to your computer and use it in GitHub Desktop.
# With a callback
def test():
def handle_user(username, first_name, last_name, exception=None):
if exception:
# Blow up
return
print username, first_name, last_name
get_user_id(10, handle_user)
# With tornado.gen interface
@gen.async
def test2():
username, first_name, last_name, exception = yield gen.Task(get_user_id, 10)
if exception:
# Blow up
return
print username, first_name, last_name
# User module
def get_user_id(user_id, callback):
async.run(da.read_user, callback, user_id)
# DA module
def read_user(user_id):
# Synchronous call here
user = User.objects.get(user_id)
if user is None:
raise Exception("Missing user")
return user.username, user.first_name, user.last_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment