Created
November 16, 2022 22:46
-
-
Save tiandiao123/f9643c7bd1634db015444e59e3cb9008 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# modified codes from https://www.bilibili.com/video/BV1oa411b7c9/?spm_id_from=333.999.0.0&vd_source=0e3bf657889554538e4fce27455e8e66 | |
import os | |
import asyncio | |
import time | |
async def print_info(waiting_time, info): | |
await asyncio.sleep(waiting_time) | |
return "{} --- {}".format(waiting_time, info) | |
async def main(): | |
create_tasks = [] | |
for i in range(10): | |
task = asyncio.create_task(print_info(i, "demo")) | |
create_tasks.append(task) | |
print(f"start time : {time.strftime('%X')}") | |
ret = await asyncio.gather(*create_tasks) | |
print(ret) | |
print(f"finishing time : {time.strftime('%X')}") | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment