Skip to content

Commit 7804c96

Browse files
add counter
1 parent a0f1b7c commit 7804c96

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

concurency/io_threading.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88
thread_local = threading.local()
99

1010
def get_session():
11+
'''
12+
So each thread will create a single session the first time it calls get_session() and then will simply use that session on each subsequent call throughout its lifetime.
13+
'''
1114
if not hasattr(thread_local, "session"):
1215
thread_local.session = requests.Session()
1316
return thread_local.session
1417

15-
def download_site(url, session):
18+
def download_site(url):
1619
session = get_session()
1720
with session.get(url) as response:
21+
1822
print(f"Read {len(response.content)} from {url}")
1923

24+
2025
def download_all_sites(sites):
21-
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
26+
with concurrent.futures.ThreadPoolExecutor(max_workers=25) as executor:
2227
executor.map(download_site, sites)
23-
28+
29+
2430
if __name__ == "__main__":
2531
sites = [
2632
"https://www.jython.org",

0 commit comments

Comments
 (0)