, generators asyncio
coroutines - . , () . Genarators - .
asyncio
, :
import asyncio
def main():
yield from asyncio.sleep(1)
print('done')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
:
done
:
import asyncio
def main():
print('done')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
:
TypeError: An asyncio.Future, a coroutine or an awaitable is required
( ) asyncio.coroutine
decorator :
import asyncio
@asyncio.coroutine
def main():
print('done')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
:
done
, , : Python 3.5 yield from
async def
await
, , .
import asyncio
async def main():
print('done')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())