[Python-Dev] cpython (3.3): Tweak the threaded example in concurrent.futures (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Tue Oct 16 14:58:18 CEST 2012
- Previous message: [Python-Dev] [Python-checkins] cpython (merge 3.3 -> default): Merge issue #15936: Add link from os.urandom to random.SystemRandom
- Next message: [Python-Dev] cpython (3.3): Tweak the threaded example in concurrent.futures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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(maxworkers=5) as executor: - futuretourl = dict((executor.submit(loadurl, url, 60), url) - for url in URLS) - - for future in concurrent.futures.ascompleted(futuretourl): - url = futuretourl[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 + loadurls = [executor.submit(loadurl, url, 60) for url in URLS] + for future, url in zip(loadurls, 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
- Previous message: [Python-Dev] [Python-checkins] cpython (merge 3.3 -> default): Merge issue #15936: Add link from os.urandom to random.SystemRandom
- Next message: [Python-Dev] cpython (3.3): Tweak the threaded example in concurrent.futures
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]