[Python-ideas] async/await in Python

Yury Selivanov yselivanov.ml at gmail.com
Sun Apr 19 20:44:00 CEST 2015


Hi Antoine,

On 2015-04-19 2:36 PM, Antoine Pitrou wrote:
> On Fri, 17 Apr 2015 20:19:42 +0000 (UTC)
> Victor Stinner <victor.stinner at gmail.com>
> wrote:
>> They are almost
>> required to make asyncio usage easier. "async for" would help database ORMs
>> or the aiofiles project (run file I/O in threads). "async with" helps also ORMs.
> I don't understand how it would help ORMs in any way. ORMs run database
> requests transparently when the user requests an attribute, which is
> completely at odds with the approach of explicitly marking (either
> through "yield from" or "await") all potentially yielding operations.

It depends on the ORM.

It's possible to completely describe the shape of the requested
data; ORM then will query the data and lazily unpack it for
the user with a nice object interface.  Queries in __getattr__
are bad because of many reasons.

What will really help database drivers, is the proposed
'async for' and 'async with'.

'async for' allows you to create a cursor that supports
asynchronous iteration protocol, and can prefetch data
to make iteration efficient.

'async with' enables to have sane transaction context
managers, i.e. the ones that can actually commit changes
in their '__aexit__' coroutine.

Thanks,
Yury



More information about the Python-ideas mailing list