3 ms·
do async comprehensions ( https://www.python.org/dev/peps/pep-0530/#asynchronous-comprehensions https://www.python.org/dev/peps/pep-0530/#asynchronous-compr...
by gregn610 10y ago
do async comprehensions ( https://www.python.org/dev/peps/pep-0530/#asynchronous-comprehensions https://www.python.org/dev/peps/pep-0530/#asynchronous-compr... ) give you concurrency? Or are they a building block to getting that in the future?
- RedCrowbar 10y agoYes, async comprehensions are concurrent like all other async mechanisms in Python 3 are. But you are likely thinking about parallelism, not concurrency, in which case the answer is also yes, if you use thread or process executors for tasks.
- dbcurtis 10y agoasync in general gets you concurrency. async def/await is syntactic sugar around generators built with __iter__ and __next__. It is totally possible to do cooperative multitasking with __iter__, __next__, yield, yield from. What this is doing is painting in some of the missing corners of the syntax. Anything you can do with a list comprehension can be done with a for loop, less tersely, often but not always less readably (choose wisely). This new syntax allows you to write comprehensions with asynchronous behavior that in 3.5 and earlier requires you to write a loop. Progress is in the eye of the beholder. "Code is read more often than it is written." Please chose the most readable form.