If you paste it in the Interactive Console, it will work as it is. In this case, since the time-consuming do_some is operated in parallel, the processing time is shorter than when it is executed in series.
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
Recommended Posts