Skip to content

Commit ac5faaf

Browse files
committed
add async/await sample
1 parent 183acda commit ac5faaf

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

samples/async/async_hello2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import threading
5+
import asyncio
6+
7+
async def hello():
8+
print('Hello world! (%s)' % threading.currentThread())
9+
await asyncio.sleep(1)
10+
print('Hello again! (%s)' % threading.currentThread())
11+
12+
loop = asyncio.get_event_loop()
13+
tasks = [hello(), hello()]
14+
loop.run_until_complete(asyncio.wait(tasks))
15+
loop.close()

samples/async/async_wget2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import threading
5+
import asyncio
6+
7+
async def hello():
8+
print('Hello world! (%s)' % threading.currentThread())
9+
await asyncio.sleep(1)
10+
print('Hello again! (%s)' % threading.currentThread())
11+
12+
loop = asyncio.get_event_loop()
13+
tasks = [hello(), hello()]
14+
loop.run_until_complete(asyncio.wait(tasks))
15+
loop.close()

0 commit comments

Comments
 (0)