import time
import asyncio
import types
async def fetch_coroutine():
print("start")
response = await _sleep()
print("end")
return response
async def _sleep():
for i in range(3):
print(i)
await sleep()
return True
@types.coroutine
def sleep():
yield time.sleep(1)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
tasks = [
fetch_coroutine(),
fetch_coroutine(),
]
loop.run_until_complete(asyncio.wait(tasks))
print('All fib finished.')
loop.close()
网友评论