Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6d5cf3

Browse files
committed
A dict comprehension is much prettier (thanks Antoine)
1 parent 5ecd004 commit d6d5cf3

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Doc/library/concurrent.futures.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,9 @@ ThreadPoolExecutor Example
144144
# We can use a with statement to ensure threads are cleaned up promptly
145145
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
146146
# Start the load operations and mark each future with its URL
147-
load_urls = [executor.submit(load_url, url, 60) for url in URLS]
148-
for future, url in zip(load_urls, URLS):
149-
future.url = url
150-
for future in concurrent.futures.as_completed(load_urls):
151-
url = future.url
147+
future_to_url = {executor.submit(load_url, url, 60):url for url in URLS}
148+
for future in concurrent.futures.as_completed(future_to_url):
149+
url = future_to_url[url]
152150
try:
153151
data = future.result()
154152
except Exception as exc:

0 commit comments

Comments
 (0)