Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Last active November 15, 2022 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YiLi225/71820e8a12c40db7e9b1bd4cf0f54114 to your computer and use it in GitHub Desktop.
Save YiLi225/71820e8a12c40db7e9b1bd4cf0f54114 to your computer and use it in GitHub Desktop.
## 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