Interactive interface for browsing global, full-resolution satellite imagery
fetch gc and colormaps with native concurrency
Jason Kentf5794cc2ff18
diff --git a/tasks/python3/getCapabilities.py b/tasks/python3/getCapabilities.pyindex 34351bfe8..9dc8bb8a5 100755--- a/tasks/python3/getCapabilities.py+++ b/tasks/python3/getCapabilities.py@@ -1,7 +1,6 @@#!/usr/bin/env python-from concurrent.futures import as_completed, wait, ThreadPoolExecutor-from requests_futures.sessions import FuturesSession+from concurrent.futures import ThreadPoolExecutorfrom optparse import OptionParserfrom datetime import datetimefrom collections import OrderedDict@@ -117,26 +116,29 @@ def process_remote(entry):print(('error: %s: %s' % (url, str(e))))print((str(traceback.format_exc())))+# Fetch a single colormap and write to file+def process_single_colormap(link):+ try:+ response = http.request("GET", link)+ contents = response.data+ output_file = os.path.join(colormaps_dir, os.path.basename(link))+ with open(output_file, "w") as fp:+ fp.write(contents.decode('utf-8'))+ except Exception as e:+ sys.stderr.write("%s: WARN: Unable to fetch %s: %s\n" %+ (prog, link, str(e)))+ global warning_count+ warning_count += 1+# Fetch every colormap from the API and write response to file systemdef process_colormaps():print("%s: Fetching %d colormaps..." % (prog, len(colormaps)))sys.stdout.flush()if not os.path.exists(colormaps_dir):os.makedirs(colormaps_dir)- with FuturesSession(max_workers=100) as fs:- futures = { fs.get(link):link for link in colormaps.values() }- for future in as_completed(futures):- fileName = futures[future]- try:- data = future.result()- output_file = os.path.join(colormaps_dir, os.path.basename(fileName))- with open(output_file, "w") as fp:- fp.write(data.text)- except Exception as e:- sys.stderr.write("%s: WARN: Unable to fetch %s: %s\n" %- (prog, link, str(e)))- global warning_count- warning_count += 1+ with ThreadPoolExecutor(max_workers=20) as executor:+ for link in colormaps.values():+ executor.submit(process_single_colormap, link)# Fetch every vectorstyle from the API and write response to file systemdef process_vectorstyles():@@ -180,20 +182,18 @@ def process_vectordata():tolerant = config.get("tolerant", False)if "wv-options-fetch" in config:- executor = ThreadPoolExecutor(3)- gc_futures = []- for entry in config["wv-options-fetch"]:- try:- remote_count += 1- gc_futures.append(executor.submit(process_remote, entry))- except Exception as e:- if tolerant:- warning_count += 1- sys.stderr.write("%s: WARN: %s\n" % (prog, str(e)))- else:- error_count += 1- sys.stderr.write("%s: ERROR: %s\n" % (prog, str(e)))- wait(gc_futures)+ with ThreadPoolExecutor(max_workers=3) as executor:+ for entry in config["wv-options-fetch"]:+ try:+ remote_count += 1+ executor.submit(process_remote, entry)+ except Exception as e:+ if tolerant:+ warning_count += 1+ sys.stderr.write("%s: WARN: %s\n" % (prog, str(e)))+ else:+ error_count += 1+ sys.stderr.write("%s: ERROR: %s\n" % (prog, str(e)))if colormaps:process_colormaps()if vectorstyles: