Re:A Hitchhiker’s Guide to Asynchronous Programming
by crazyguitar on Saturday February 29, 2020 @02:03AM
(#22449378)
Yeah! I know that @coroutine and yield from are deprecated. This article focuses on how coroutines cooperate with event loops in Python. You remind me that I should add a warning to inform your information. Thanks.
Re:A Hitchhiker’s Guide to Asynchronous Programming
by nurettin on Saturday February 29, 2020 @02:12AM
(#22449405)
what if we yield from an async function without the @coroutine decorator? That is also an AsyncGenerator. Or is the scope of deprecation solely concerned with the @coroutine decorator?
Re:A Hitchhiker’s Guide to Asynchronous Programming
by crazyguitar on Saturday February 29, 2020 @03:53AM
(#22449690)
I think the syntax, `yield from`, and `@coroutine` are two things. `async def` + `yield from` means we delegate generator to another generator. Therefore, in the async function, using `yield from` is equal to declare an asynchronous generator function.
However, using `@coroutine` + `yield from` means we transform a generator into a generator coroutine. Because a generator is a form of coroutine, in Python 3.4, `@coroutine` turns a function or a future into a generator function. Note that if a function is a generator function, `@coroutine` does not do anything. Based on the document, Python recommends using `async def` instead of `@coroutine` to declare a coroutine because `@coroutine` will be removed in Python 3.10.
Re:A Hitchhiker’s Guide to Asynchronous Programming
by nurettin on Saturday February 29, 2020 @05:45AM
(#22450002)
we can transform async generators into coroutines (async functions) by creating a new async function that simply starts iterating over the async generators, so every name is overloaded which makes communication kinda hard. I will just assume the happy case of @coroutine getting a downgrade. Don't use it anyway.
I just want to inform that "yield from" and "@coroutine" are now deprecated. So the article needs a bit of an update:
Note: Support for generator-based coroutines is deprecated and is scheduled for removal in Python 3.10.
References: - https://docs.python.org/3/library/asyncio-task.html#generato... - https://docs.python.org/3/whatsnew/3.7.html - https://bugs.python.org/issue36921