Sujet : Re: Await expressions
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 01. Feb 2024, 17:39:44
Autres entêtes
Organisation : Stefan Ram
Message-ID : <await-20240201173737@ram.dialup.fu-berlin.de>
References : 1 2
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Heck, even of the respected members of this newsgroup, IIRC, no one
mentioned "__await__". So, let's give a big shoutout to Victor!
It should be possible to understand "await" in isolation (in
the spirit of the quotation I posted to "comp.lang.lisp" today.)
For example, use "await" without using "asycnio". So here's
an example program in that direction I just wrote.
main.py
class o_class():
def __await__( self ):
print( "__await__ called." )
return iter( [ 'a', 'b', 'c' ])
o = o_class()
async def f():
while 1: await o
for i, j in enumerate( f().__await__() ):
print( j )
if 5 == i: break
sys.stdout
__await__ called.
a
b
c
__await__ called.
a
b
c
(Then, it should also be interesting to understand how asyncio
uses "await" to implement asynchronous I/O.)