Re: [Python-Dev] cpython (3.3): Tweak the threaded example in concurrent.futures

2012年10月16日 06:02:14 -0700

On 2012年10月16日 14:51:21 +0200 (CEST)
nick.coghlan <[email protected]> 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
[email protected]
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