반응형
import asyncio
import time
async def say_after(delay, what):
await asyncio.sleep(delay)
print(what)
async def main():
print(f"started at {time.strftime('%X')}")
await say_after(1, 'hello')
await say_after(2, 'world')
print(f"finished at {time.strftime('%X')}")
asyncio.run(main())
started at 17:13:52
hello
world
finished at 17:13:55
아래 글에 코루틴과 테스크를 비교분석해둔 글도 존재한다.
https://kdw9502.tistory.com/6?category=779910
반응형
'Basic > Python' 카테고리의 다른 글
asyncio를 이용한 파이썬 비동기 처리하기 (0) | 2022.04.14 |
---|---|
Python에서 파일 존재여부 확인 방법 (0) | 2022.04.11 |
paramiko를 이용한 리눅스 sftp 다운로드 방법 (0) | 2022.04.08 |
[openpyxl] 11. 파이썬을 이용한 엑셀 기타 정리본 (0) | 2021.10.30 |
[openpyxl] 10. 파이썬을 이용한 엑셀 이미지 삽입 (0) | 2021.10.29 |
[openpyxl] 9. 파이썬을 이용한 엑셀 셀 병합 및 해제 (0) | 2021.10.27 |