We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c808972 commit 360e8a0Copy full SHA for 360e8a0
understanding-asynchronous-programming/example_5.py
@@ -4,13 +4,14 @@
4
5
6
def task(name, work_queue):
7
- while not work_queue.empty():
8
- url = work_queue.get()
9
- print(f"Task {name} getting URL: {url}")
10
- et = ET()
11
- requests.get(url)
12
- print(f"Task {name} total elapsed time: {et():.1f}")
13
- yield
+ with requests.Session() as session:
+ while not work_queue.empty():
+ url = work_queue.get()
+ print(f"Task {name} getting URL: {url}")
+ et = ET()
+ session.get(url)
+ print(f"Task {name} total elapsed time: {et():.1f}")
14
+ yield
15
16
17
def main():
0 commit comments