A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-October/122188.html below:

Tweak the threaded example in concurrent.futures

[Python-Dev] cpython (3.3): Tweak the threaded example in concurrent.futures [Python-Dev] cpython (3.3): Tweak the threaded example in concurrent.futuresAntoine Pitrou solipsis at pitrou.net
Tue Oct 16 14:58:18 CEST 2012
On Tue, 16 Oct 2012 14:51:21 +0200 (CEST)
nick.coghlan <python-checkins at 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


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4