Skip to content

Commit 631c464

Browse files
authored
Merge pull request #9035 from Irenetitor/pr/15-Python
#15-Python
2 parents f7434a8 + 758ad5f commit 631c464

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import datetime
2+
import asyncio
3+
4+
async def task(name: str, duration: int):
5+
print(f"Task: {name}. Duration: {duration}s. Start: {datetime.datetime.now()}")
6+
await asyncio.sleep(duration)
7+
print(f"Task: {name}. End: {datetime.datetime.now()}")
8+
9+
#asyncio.run(task("1", 4))
10+
11+
12+
13+
#Extra Exercise
14+
15+
async def async_tasks():
16+
await asyncio.gather(task("c", 3), task("B", 2), task("A", 1))
17+
18+
await task("D", 1)
19+
20+
#asyncio.run(async_tasks())
21+
22+
async def main():
23+
await task("1", 4) #part 1
24+
25+
await async_tasks() #part2
26+
27+
28+
asyncio.run(main())

0 commit comments

Comments
 (0)