安装
1
pip install awaits
使用方法,只需向同步函数添加@awaitable装饰器,就可以把该同步函数专成异步调用,如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import time
import asyncio
from awaits.awaitable import awaitable
@awaitable
def test(seconds=1):
time.sleep(seconds)
async def async_test():
print('start')
await test(2)
print('done')
loop = asyncio.get_event_loop()
loop.run_until_complete(async_test())
loop.close()