-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_ad_3_4.py
More file actions
53 lines (39 loc) · 1.16 KB
/
py_ad_3_4.py
File metadata and controls
53 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Section 3
Concurrency, CPU Bound vs I/O Bound - I/O Bound(1) - Synchronous
Keyword - I/O Bound, requests
"""
# I/O-Bound Sync 예제(https://realpython.com/python-concurrency/#synchronous-version)
# pip install requests
import requests
import time
# 실행함수1(다운로드)
def request_site(url, session):
# 세션 확인
# print(session)
# print(session.headers)
with session.get(url) as response:
print(f"[Read Contents : {len(response.content)}, Status Code : {response.status_code}] from {url}")
# 실행함수2
def request_all_site(urls):
with requests.Session() as session:
for url in urls:
request_site(url, session)
def main():
# 테스트 URLS
urls = [
"https://www.jython.org",
"http://olympus.realpython.org/dice",
"https://realpython.com/"
] * 3
# 실행시간 측정
start_time = time.time()
# 실행
request_all_site(urls)
# 실행 시간 종료
duration = time.time() - start_time
print()
# 결과 출력
print(f"Downloaded {len(urls)} sites in {duration} seconds")
if __name__ == "__main__":
main()