File tree Expand file tree Collapse file tree 4 files changed +14
-18
lines changed
understanding-asynchronous-programming Expand file tree Collapse file tree 4 files changed +14
-18
lines changed Original file line number Diff line number Diff line change 44
55
66def task (name , queue ):
7- text = '' .join ([f'Task { name } elapsed time: ' , '{:.2f}' ])
8- timer = Timer (text = text )
7+ timer = Timer (text = f"Task { name } elapsed time: {{:.1f}}" )
98 while not queue .empty ():
109 delay = queue .get ()
1110 print (f"Task { name } running" )
@@ -19,18 +18,18 @@ def main():
1918 """
2019 This is the main entry point for the program
2120 """
22- # Create the queue of ' work'
21+ # Create the queue of " work"
2322 work_queue = queue .Queue ()
2423
25- # Put some ' work' in the queue
24+ # Put some work in the queue
2625 for work in [15 , 10 , 5 , 2 ]:
2726 work_queue .put (work )
2827
2928 tasks = [task ("One" , work_queue ), task ("Two" , work_queue )]
3029
3130 # Run the tasks
3231 done = False
33- with Timer (text = ' \n Total elapsed time: {:.2f}' ):
32+ with Timer (text = " \n Total elapsed time: {:.1f}" ):
3433 while not done :
3534 for t in tasks :
3635 try :
Original file line number Diff line number Diff line change 33
44
55async def task (name , work_queue ):
6- text = '' .join ([f'Task { name } elapsed time: ' , '{:.2f}' ])
7- timer = Timer (text = text )
6+ timer = Timer (text = f"Task { name } elapsed time: {{:.1f}}" )
87 while not work_queue .empty ():
98 delay = await work_queue .get ()
109 print (f"Task { name } running" )
@@ -17,15 +16,15 @@ async def main():
1716 """
1817 This is the main entry point for the program
1918 """
20- # Create the queue of ' work'
19+ # Create the queue of " work"
2120 work_queue = asyncio .Queue ()
2221
23- # Put some ' work' in the queue
22+ # Put some " work" in the queue
2423 for work in [15 , 10 , 5 , 2 ]:
2524 await work_queue .put (work )
2625
2726 # Run the tasks
28- with Timer (text = ' \n Total elapsed time: {:.2f}' ):
27+ with Timer (text = " \n Total elapsed time: {:.1f}" ):
2928 await asyncio .gather (
3029 asyncio .create_task (task ("One" , work_queue )),
3130 asyncio .create_task (task ("Two" , work_queue )),
Original file line number Diff line number Diff line change 44
55
66def task (name , work_queue ):
7- text = '' .join ([f'Task { name } elapsed time: ' , '{:.2f}' ])
8- timer = Timer (text = text )
7+ timer = Timer (text = f"Task { name } elapsed time: {{:.1f}}" )
98 with requests .Session () as session :
109 while not work_queue .empty ():
1110 url = work_queue .get ()
@@ -20,10 +19,10 @@ def main():
2019 """
2120 This is the main entry point for the program
2221 """
23- # Create the queue of ' work'
22+ # Create the queue of " work"
2423 work_queue = queue .Queue ()
2524
26- # Put some ' work' in the queue
25+ # Put some " work" in the queue
2726 for url in [
2827 "http://google.com" ,
2928 "http://yahoo.com" ,
@@ -39,7 +38,7 @@ def main():
3938
4039 # Run the tasks
4140 done = False
42- with Timer (text = ' \n Total elapsed time: {:.2f}' ):
41+ with Timer (text = " \n Total elapsed time: {:.1f}" ):
4342 while not done :
4443 for t in tasks :
4544 try :
Original file line number Diff line number Diff line change 44
55
66async def task (name , work_queue ):
7- text = '' .join ([f'Task { name } elapsed time: ' , '{:.2f}' ])
8- timer = Timer (text = text )
7+ timer = Timer (text = f"Task { name } elapsed time: {{:.1f}}" )
98 async with aiohttp .ClientSession () as session :
109 while not work_queue .empty ():
1110 url = await work_queue .get ()
@@ -36,7 +35,7 @@ async def main():
3635 await work_queue .put (url )
3736
3837 # Run the tasks
39- with Timer (text = '\n Total elapsed time: {:.2f }' ):
38+ with Timer (text = '\n Total elapsed time: {:.1f }' ):
4039 await asyncio .gather (
4140 asyncio .create_task (task ("One" , work_queue )),
4241 asyncio .create_task (task ("Two" , work_queue ))
You can’t perform that action at this time.
0 commit comments