Thank you very much for this, Guido, it was really helpful.

I agree: the docs need an improvement to clarify the points you made.
I will be able to submit a patch as soon as I wrap up my book. The
deadline is soon.

Cheers,

Luciano


On Sun, Mar 22, 2015 at 7:22 PM, Guido van Rossum <gu...@python.org> wrote:
> They're totally different. async() is for those cases where you have
> something that's either a coroutine or a Future and what you need is a
> Future (e.g. because you want to add a callback). It will return the Future
> unchanged but wrap the coroutine in a Task. (Note that Task subclasses
> Future so a Task will also be returned unchanged.)
>
> OTOH create_task() *always* creates a new Task, and the argument must
> *always* be a coroutine. It is *nearly* the same as just using Task() -- the
> difference is that create_task() may be overridden by certain EventLoop
> subclasses to return a task that behaves better with some other framework
> (e.g. Tornado).
>
> Also note that async() calls create_task(), but only when it decides to
> create a new task.
>
> Maybe the docs need an upgrade, please submit a patch.
>
> On Sun, Mar 22, 2015 at 7:32 AM, Luciano Ramalho <luci...@ramalho.org>
> wrote:
>>
>> I understand these do almost the same thing, and asyncio.async can
>> even get a loop keyword argument so it's as flexible as
>> loop.create_task, which it uses internally.
>>
>> So my question is: are both being kept going forward, or is this
>> redundancy just a temporary compatibility measure before asyncio.async
>> is deprecated?
>>
>> The docs seem to imply ever-so-slightly that create_task is better and
>> async should be used "to support also older Python versions".
>>
>> Cheers,
>>
>> Luciano
>>
>> --
>> Luciano Ramalho
>> |  Author of Fluent Python (O'Reilly, 2015)
>> |     http://shop.oreilly.com/product/0636920032519.do
>> |  Professor em: http://python.pro.br
>> |  Twitter: @ramalhoorg
>
>
>
>
> --
> --Guido van Rossum (python.org/~guido)



-- 
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
|     http://shop.oreilly.com/product/0636920032519.do
|  Professor em: http://python.pro.br
|  Twitter: @ramalhoorg

Reply via email to