loading...

Use ndb.tasklet in GAE

arvelt profile image arvelt ・1 min read
from time import sleep
from google.appengine.ext import ndb


@ndb.tasklet
def do_some(time):
  yield ndb.sleep(time)
  raise ndb.Return(time)

@ndb.tasklet
def foo():
  a, b = yield (do_some(3), do_some(3))
  raise ndb.Return(a + b)

def main():
  f = foo()
  x = f.get_result()
  print x

main() #Execution time is 3 not 6

Discussion

markdown guide