Commit bb28e311 authored by Nick Coghlan's avatar Nick Coghlan

Merge concurrent.futures dict comp tweak from 3.3

parents 3f9d49bd b0004a9b
...@@ -144,11 +144,9 @@ ThreadPoolExecutor Example ...@@ -144,11 +144,9 @@ ThreadPoolExecutor Example
# We can use a with statement to ensure threads are cleaned up promptly # We can use a with statement to ensure threads are cleaned up promptly
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
# Start the load operations and mark each future with its URL # Start the load operations and mark each future with its URL
load_urls = [executor.submit(load_url, url, 60) for url in URLS] future_to_url = {executor.submit(load_url, url, 60):url for url in URLS}
for future, url in zip(load_urls, URLS): for future in concurrent.futures.as_completed(future_to_url):
future.url = url url = future_to_url[url]
for future in concurrent.futures.as_completed(load_urls):
url = future.url
try: try:
data = future.result() data = future.result()
except Exception as exc: except Exception as exc:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment