1import asyncio
2
3
4async def hello():
5 print("hello")
6
7
8async def hello_timer1():
9 while True:
10 print("hello timer1")
11 await asyncio.sleep(1)
12
13
14async def hello_timer2():
15 while True:
16 print("hello timer2")
17 await asyncio.sleep(1)
18
19
20async def hello_timeout():
21 print("hello timeout")
22 await asyncio.sleep(10)
23
24
25async def main():
26 await hello()
27
28 try:
29 await asyncio.wait_for(hello_timeout(), 3)
30 except Exception as e:
31 print("hello timeout done:", e)
32
33 await asyncio.gather(
34 hello_timer1(),
35 hello_timer2(),
36 )
37
38
39if __name__ == "__main__":
40 asyncio.run(main())