I just read PEP0492 talking about the new approach on coroutines but the PEP failed to make me understand the difference between generator-based coroutines and native ones.
Well, conventionally the way to write coroutines involved callbacks. Even though callbacks might be convenient initially, but in my opinion, they lead to highly complicated and complex code, which is not pythonic to say the least. Besides, yield
(especially yield from
since python 3.3), has made implementing coroutines a lot easier and pythonic.
With generators, you can easily divide your code into initial part and callbacks.
@asyncio.coroutine
def print_sum(x, y):
result = yield from compute(x, y)
#write callback code
print("%s + %s = %s" % (x, y, result))