On Wed, Nov 7, 2012 at 7:05 PM, momiji1 <slove...
> python3.3 released days ago. the biggest new feature is yield from
> Would that make coding easier?
> in previous version, if you want to make gen.task work at somewhere, you
> must modify all functions at the very beginning passing a callback. though
> most of the callback is meaningless.
> in 3.3. you can simply use yield from to call the function, you don't have
> to make all functions become asynchronous ,isn't it?
Python 3.3 does offer some improvements for generator-based code,
especially the fact that you can have "yield" and "return" in the same
function, so you don't need to pass callbacks around explicitly. You can
use some parts of this with @gen.engine today:
def foo(args, callback):
# Entry points must still take callbacks and be decorated with
# Undecorated generators can be called with yield from
result = yield from async_helper(args)
# Functions called with "yield from" do not take a callback and are not
# Objects yielded here will be passed through to the caller's
x = yield gen.Task(...)
Unfortunately, to take full advantage of this (and remove the dichotomy
between entry points that need decorators and callbacks, and inner
functions that must not have either) you need a generator scheduler that
was designed with "yield from" in mind. Such a scheduler would only work
in Python 3.3+, so it will be a while before I'm willing to put something
like that in Tornado itself. However, there is talk of adding a "yield
from"-based async framework to the standard library in python 3.4.