Created
October 14, 2022 13:05
-
-
Save junhg0211/208a44dcea4198ff572cc5aeaa473fbc to your computer and use it in GitHub Desktop.
python asyncio study
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
import asyncio | |
import random | |
import time | |
def fetch_something(): | |
time.sleep(duration := random.random() / 10) | |
return duration | |
def another_thing(): | |
print('another_thing이 실행됐어요!') | |
return 1 | |
async def long_work(): | |
for _ in range(100): | |
await asyncio.sleep(0) | |
print(fetch_something()) | |
async def main(): | |
lwc = asyncio.create_task(long_work()) | |
await asyncio.sleep(2) | |
another_thing() | |
await lwc | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment