Last active
November 15, 2022 21:12
-
-
Save YiLi225/71820e8a12c40db7e9b1bd4cf0f54114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Errands: [start_time, duration] | |
errandsDict = { | |
'Grocery Shopping': [11, 2], | |
'Return Packages': [9, 1], | |
'Pick Up Kids': [6, 1], | |
} | |
async def errands_log(task, start_time, time_to_finish): | |
await asyncio.sleep(start_time) | |
print(f"({task}) starting at {start_time}am") | |
await asyncio.sleep(time_to_finish) | |
print(f"({task}) done at {start_time+time_to_finish}am\n ======;") | |
## Asynchronous tasks | |
async def run_errands(): | |
errands = [] | |
for errand, (start_time, time_to_finish) in errandsDict.items(): | |
errands.append(errands_log(errand, start_time, time_to_finish)) | |
## gather all information after run | |
await asyncio.gather(*errands) | |
asyncio.run(run_errands()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment