# file test.py
import asyncio
from inspect import iscoroutine
from typing import Any
async def a():
print('run a')
asyncio.sleep(1)
return 1
async def b():
# type: () -> Any
print('run b')
return a()
async def g():
# type: () -> Any
print('run g')
s = b()
while iscoroutine(s):
print('in g', s)
s = await s
return s
if __name__ == '__main__':
loop = asyncio.get_event_loop()
a = loop.run_until_complete(g())
print('finish ', a)
Run Code Online (Sandbox Code Playgroud)
当使用python3.6.6运行以上代码时,我得到:
run g
in g <coroutine object b at 0x10a980938> …Run Code Online (Sandbox Code Playgroud)