adding chapter 7 source code

This commit is contained in:
muassif
2021-03-31 09:22:38 +04:00
committed by GitHub
parent 9589675a50
commit f88527eef4
20 changed files with 618 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
#asyncio2.py to build and run coroutines in parallel
import asyncio
import time
async def say(delay, msg):
await asyncio.sleep(delay)
print(msg)
async def main ():
task1 = asyncio.create_task( say(1, 'Good'))
task2 = asyncio.create_task( say(1, 'Morning'))
print("Started at ", time.strftime("%X"))
await task1
await task2
print("Stopped at ", time.strftime("%X"))
asyncio.run(main())