Hi Guido,

Thanks for the answer and thanks for the trick.

I figured it out your code. In that sample the yields run concurrently they
don't in parallel. What I'm really trying to do is *paralleling *the asyncs
*yielding *a tuple, but it's possible one of them will be None and in that
case It'll throw an exception: "None object has no attribute .get_async()".

How can I avoid this exception?

Thanks in advance and regards.


Saludos.
Moisés Belchín.


2013/1/30 Guido van Rossum <gu...@python.org>

> On Wed, Jan 30, 2013 at 9:00 AM, Moises Belchin <moisesbelc...@gmail.com>
> 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 google-appengine+unsubscr...@googlegroups.com.
> To post to this group, send email to google-appengine@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-appengine?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to