我收到此错误:
D:\pythonstuff\demo.py:28: DeprecationWarning: 自 Python 3.8 起不推荐将协程对象显式传递给 asyncio.wait(),并计划在 Python 3.11 中删除。等待 asyncio.wait([
等了1秒!
等了5秒!
经过的时间:0小时:0分:5秒进程以退出代码 0 结束
当我运行代码时:
import asyncio
import time
class class1():
async def function_inside_class(self):
await asyncio.sleep(1)
print("Waited 1 second!")
async def function_inside_class2(self):
await asyncio.sleep(5)
print("Waited 5 second!")
def tic():
global _start_time
_start_time = time.time()
def tac():
t_sec = round(time.time() - _start_time)
(t_min, t_sec) = divmod(t_sec,60)
(t_hour,t_min) = divmod(t_min,60)
print('Time passed: {}hour:{}min:{}sec'.format(t_hour,t_min,t_sec))
object = class1()
async def main():
tic()
await asyncio.wait([
object.function_inside_class(),
object.function_inside_class2()
])
tac() …Run Code Online (Sandbox Code Playgroud)