Skip to content

Instantly share code, notes, and snippets.

@junhg0211
Created October 14, 2022 13:05
Show Gist options
  • Save junhg0211/208a44dcea4198ff572cc5aeaa473fbc to your computer and use it in GitHub Desktop.
Save junhg0211/208a44dcea4198ff572cc5aeaa473fbc to your computer and use it in GitHub Desktop.
python asyncio study
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