[Python-ideas] An async facade? (was Re: [Python-Dev] Socket timeout and completion based sockets)

Antoine Pitrou solipsis at pitrou.net
Fri Nov 30 20:27:10 CET 2012

On Fri, 30 Nov 2012 11:04:09 -0800
Guido van Rossum <guido at python.org> wrote:
> Futures or callbacks, that's the question...
> Richard and I have even been considering APIs like this:
> res = obj.some_call(<args>)
> if isinstance(res, Future):
>     res = yield res
> or
> res = obj.some_call(<args>)
> if res is None:
>     res = yield <magic>
> where <magic> is some call on the scheduler/eventloop/proactor that
> pulls the future out of a hat.
> The idea of the first version is simply to avoid the Future when the
> result happens to be immediately ready (e.g. when calling readline()
> on some buffering stream, most of the time the next line is already in
> the buffer); the point of the second version is that "res is None" is
> way faster than "isinstance(res, Future)" -- however the magic is a
> little awkward.

This premature optimization looks really ugly to me. I'm strongly -1
on both idioms.



More information about the Python-ideas mailing list