coro1 함수는 3초마다 1씩 증가하는 값 출력하는 함수
coro2 함수는 input 값이 들어오면 입력한 값 출력하는 함수
import asyncio as aio
async def coro1():
i = 1
while True:
print(i)
i = i+1
await aio.sleep(3)
async def coro2(loop):
while True:
msg = await loop.run_in_executor(None, input, ": ")
print('->', msg)
async def main():
loop = aio.get_event_loop()
task1 = loop.create_task(coro1())
task2 = loop.create_task(coro2(loop))
await task1
await task2
aio.run(main())
'시행착오 > [python]' 카테고리의 다른 글
파이썬 requests 비동기로 할 때 arguments 여러개 보내는 법 (0) | 2021.03.30 |
---|---|
[python] logging Module - 파이썬 로그 남기기 시행착오 정리 (0) | 2021.03.23 |
[python] 딕셔너리 에러 RuntimeError: dictionary changed size during iteration (0) | 2021.01.19 |
오프라인 centos에 파이썬 설치 및 pip install 과정 정리 (0) | 2020.12.29 |
리눅스에서(cent os7) 원하는 파이썬 버전(python3.7)으로 가상환경 들어가기 (0) | 2020.07.21 |