]> granicus.if.org Git - python/commitdiff
A dict comprehension is much prettier (thanks Antoine)
authorNick Coghlan <ncoghlan@gmail.com>
Tue, 16 Oct 2012 13:14:03 +0000 (23:14 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Tue, 16 Oct 2012 13:14:03 +0000 (23:14 +1000)
Doc/library/concurrent.futures.rst

index 70b0fd10aee9bbb17bbd8625fda1fe62a152aac3..62d8eac69ec80a6864f75b454bfde2bcb69ba26f 100644 (file)
@@ -144,11 +144,9 @@ ThreadPoolExecutor Example
    # We can use a with statement to ensure threads are cleaned up promptly
    with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
        # Start the load operations and mark each future with its URL
-       load_urls = [executor.submit(load_url, url, 60) for url in URLS]
-       for future, url in zip(load_urls, URLS):
-           future.url = url
-       for future in concurrent.futures.as_completed(load_urls):
-           url = future.url
+       future_to_url = {executor.submit(load_url, url, 60):url for url in URLS}
+       for future in concurrent.futures.as_completed(future_to_url):
+           url = future_to_url[url]
            try:
                data = future.result()
            except Exception as exc: