asyncio (2) 썸네일형 리스트형 [Python] I/O Bound(2) - Asyncio 통신관련 비동기 처리 import asyncio import aiohttp # import requests # 패키지는 동기방식이라서 사용불가. import time async def request_site(session, url): # 세션 확인 # print(session) # print(session.headers) async with session.get(url) as response: # status_code 동기화 문제 print("Read Contents {}, from {}, stauts:{}".format(response.content_length, url, response.status)) # print("*****Read Contents {0}, from {1}".format(respo.. [Python] I/O Bound(2) - Asyncio basic 비동기 기초 샘플 코드 동시 프로그래밍 패러다임 변화 싱글코어 -> 처리향상 미미, 저하 -> 비동기 프로그래밍 -> CPU연산, DB연동, API호출 대기 시간 늘어남 => 논블로킹으로 변환 파이썬에서 비동기 프로그래밍은 개념을 잘 잡아야 함. 파이썬 3.4에서 비동기(asyncio) 표준라이브러리 등장 import time import asyncio async def exe_calculate_async(name, n): for i in range(1, n + 1): print(f'{name} -> {i} of {n} is calculating..') # time.sleep(1) # 동기 처리, 시간비교하기 좋음 await asyncio.sleep(1) # 비동기 처리, 시간비교하기 좋음 print(f.. 이전 1 다음