Skip to content

Commit b67d651

Browse files
committed
update
1 parent e3fd3f2 commit b67d651

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎async/main.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# python3 协程例子
3+
import asyncio
4+
import time
5+
6+
7+
import asyncio
8+
9+
# 在这个示例中,我们定义了一个协程 hello_world,它打印出 "Hello",然后等待一秒钟,然后再打印出 "World"。
10+
# 然后我们使用 asyncio.get_event_loop() 获取事件循环对象,然后使用 loop.run_until_complete() 运行协程,直到完成。
11+
12+
13+
async def hello_world():
14+
print("Hello")
15+
await asyncio.sleep(1)
16+
print("World")
17+
18+
loop = asyncio.get_event_loop()
19+
loop.run_until_complete(hello_world())

0 commit comments

Comments
 (0)