On Tue, 16 Oct 2012 14:51:21 +0200 (CEST)
nick.coghlan <python-check...@python.org> wrote:
>  
> +   # We can use a with statement to ensure threads are cleaned up promptly
>     with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
> -       future_to_url = dict((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[future]
> -           if future.exception() is not None:
> -               print('%r generated an exception: %s' % (url,
> -                                                        future.exception()))
> +       # 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

Adding an "url" attribute here looks a bit ugly to me. Why not use a
dict comprehension for future_to_url?

Regards

Antoine.


-- 
Software development and contracting: http://pro.pitrou.net


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to