Interactive interface for browsing global, full-resolution satellite imagery
process colormaps concurrently
Jason Kentf9cca7c39713
diff --git a/tasks/python3/processColormap.py b/tasks/python3/processColormap.pyindex 60333d68a..22a7c3596 100755--- a/tasks/python3/processColormap.py+++ b/tasks/python3/processColormap.py@@ -1,5 +1,6 @@#!/usr/bin/env python+from concurrent.futures import ProcessPoolExecutorfrom optparse import OptionParserimport osimport re@@ -133,16 +134,16 @@ def process_entries(colormap):return result-def process_file(file):- input_file = os.path.join(root, file)- id = os.path.splitext(os.path.basename(input_file))[0]+def read_file(file):+ id = os.path.splitext(os.path.basename(file))[0]if id in skips:- sys.stderr.write("%s: WARN: [%s] %s\n" % (prog, input_file,- "Skipping"))+ sys.stderr.write("%s: WARN: [%s] %s\n" % (prog, file), "Skipping")return-- with open(input_file) as fp:+ with open(file) as fp:xml = fp.read()+ return (id, xml)++def process_file(id, xml):document = xmltodict.parse(xml)colormaps = to_list(document["ColorMaps"]["ColorMap"])maps = []@@ -177,15 +178,22 @@ def process_file(file):# Mainfile_count = 0error_count = 0--for root, dirs, files in os.walk(input_dir):- for file in files:+futures = []++with ProcessPoolExecutor(max_workers=100) as readExecutor:+ for root, dirs, files in os.walk(input_dir):+ for file in files:+ input_file = os.path.join(root, file)+ futures.append(readExecutor.submit(read_file, input_file))+with ProcessPoolExecutor(max_workers=100) as writeExecutor:+ for future in futures:try:file_count += 1- process_file(file)+ (id, xml) = future.result()+ writeExecutor.submit(process_file, id, xml)except Exception as e:- sys.stderr.write("%s: ERROR: [%s] %s\n" % (prog, file, str(e)))- error_count += 1+ sys.stderr.write("%s: ERROR: %s\n" % (prog, str(e)))+ error_count += 1print("%s: %d error(s), %d file(s)" % (prog, error_count, file_count))