On Wed, Jan 30, 2013 at 9:00 AM, Moises Belchin <[email protected]> wrote: > Please take a look at this parallel tasklet code snippet #1. > > > @ndb.tasklet > def get_data_parallel(e): > usr, det = yield (e.user.get_async(), > MyKind.query(ancestor = e.key).fetch_async()) > raise ndb.Return((e, usr, det)) > > > > If e.user is None this raise an Exception. > > > I'm trying this snippet #2. However I still get Exception: "TypeError: > Expected Future, received <type 'NoneType'>: None" > > > @ndb.tasklet > def get_data_parallel(e): > usr, det = yield (e.user.get_async() if e.user else None, > MyKind.query(ancestor = e.key).fetch_async()) > raise ndb.Return((e, usr, det)) > > > How can I do something like snippet #2 ? How can I return future(None) or > future('')
You can factor it out into two yields, one of which is optional. First create a future for the query that you always want to run: f = MyKind.query(ancestor = e.key).fetch_async() # No yield! Then conditionally yield the other async request: if e.user: usr = yield from e.user.get_async() else: usr = None Finally yield the future: det = yield f The trick is that the query will run when you yield the other operation. -- --Guido van Rossum (python.org/~guido) -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-appengine?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
