3 ms·
I for one have always thought that keeping things synchronous based on select() is a better intellectual discipline and less error prone. Only in few cases you
by jojo14 7y ago
I for one have always thought that keeping things synchronous based on select() is a better intellectual discipline and less error prone. Only in few cases you are forced to use asynchronous programming. However that's not why I comment here.
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#generator-based-coroutines https://docs.python.org/3/library/asyncio-task.html#generato...
- https://docs.python.org/3/whatsnew/3.7.html https://docs.python.org/3/whatsnew/3.7.html
- https://bugs.python.org/issue36921 https://bugs.python.org/issue36921
- crazyguitar 7y agoYeah! 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.
- nurettin 7y agowhat 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?
- crazyguitar 7y agoI 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.
- nurettin 7y agowe 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.