LoginSignup
1
0

More than 5 years have passed since last update.

Google Appe Engine でndb.taskletを使う

Last updated at Posted at 2016-05-19

Interactive Consoleに貼り付ければそのまま動く。
この場合は、時間のかかるdo_someを並列に動かしているので、直列に実行した時よりも処理時間が短くなる。

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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0