forked from edyoda/python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncio-code.py
More file actions
Latest commit
25 lines (17 loc) · 489 Bytes
/
Copy pathasyncio-code.py
File metadata and controls
25 lines (17 loc) · 489 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
importasyncio
importtime
asyncdefsay_after(delay, what):
awaitasyncio.sleep(delay)
print(what)
asyncdefmain():
task1=asyncio.create_task(
say_after(1, 'hello'))
task2=asyncio.create_task(
say_after(2, 'world'))
print(f"started at {time.strftime('%X')}")
# Wait until both tasks are completed (should take
# around 2 seconds.)
awaittask1
awaittask2
print(f"finished at {time.strftime('%X')}")
asyncio.run(main())