Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products.

Python 3.10 is now generally available.

google.appengine.ext.ndb.Return

Return from a tasklet in Python 2.

Inherits From: expected_type

In Python 2, generators may not return a value. In order to return a value from a tasklet, then, it is necessary to raise an instance of this exception with the return value:

@ndb.tasklet
def get_some_stuff():
  future1 = get_something_async()
  future2 = get_something_else_async()
  thing1, thing2 = yield future1, future2
  result = compute_result(thing1, thing2)
  raise ndb.Return(result)

In Python 3, you can simply return the result:

@ndb.tasklet
def get_some_stuff():
  future1 = get_something_async()
  future2 = get_something_else_async()
  thing1, thing2 = yield future1, future2
  result = compute_result(thing1, thing2)
  return result