Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

#2508 wrap multiprocessing blocks in __main__ check

Jason Kent2b82cc62ceee
diff --git a/tasks/python3/extractConfigFromWMTS.py b/tasks/python3/extractConfigFromWMTS.py
index 79e4b3315..e027bca85 100755
--- a/tasks/python3/extractConfigFromWMTS.py
+++ b/tasks/python3/extractConfigFromWMTS.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
from datetime import datetime, date, timedelta
import json
from optparse import OptionParser
diff --git a/tasks/python3/getCapabilities.py b/tasks/python3/getCapabilities.py
index d37270e68..8f177ed2b 100755
--- a/tasks/python3/getCapabilities.py
+++ b/tasks/python3/getCapabilities.py
@@ -181,27 +181,28 @@ def process_vectordata():
futures = []
tolerant = config.get("tolerant", False)
-if "wv-options-fetch" in config:
- with ThreadPoolExecutor() as executor:
- for entry in config["wv-options-fetch"]:
- futures.append(executor.submit(process_remote, entry))
- for future in futures:
- try:
- remote_count += 1
- future.result()
- 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:
- process_vectorstyles()
- if vectordata:
- process_vectordata()
+if __name__ == "__main__":
+ if "wv-options-fetch" in config:
+ with ThreadPoolExecutor() as executor:
+ for entry in config["wv-options-fetch"]:
+ futures.append(executor.submit(process_remote, entry))
+ for future in futures:
+ try:
+ remote_count += 1
+ future.result()
+ 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:
+ process_vectorstyles()
+ if vectordata:
+ process_vectordata()
print("%s: %d error(s), %d remote(s)" % (prog, error_count, remote_count))
diff --git a/tasks/python3/processColormap.py b/tasks/python3/processColormap.py
index 9a2c8be0d..b5e43f66a 100755
--- a/tasks/python3/processColormap.py
+++ b/tasks/python3/processColormap.py
@@ -179,21 +179,21 @@ def process_file(id, xml):
file_count = 0
error_count = 0
futures = []
-
-with ProcessPoolExecutor() 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() as writeExecutor:
- for future in futures:
- try:
- file_count += 1
- (id, xml) = future.result()
- writeExecutor.submit(process_file, id, xml)
- except Exception as e:
- sys.stderr.write("%s: ERROR: [%s] %s\n" % (prog, id, str(e)))
- error_count += 1
+if __name__ == "__main__":
+ with ProcessPoolExecutor() 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() as writeExecutor:
+ for future in futures:
+ try:
+ file_count += 1
+ (id, xml) = future.result()
+ writeExecutor.submit(process_file, id, xml)
+ except Exception as e:
+ sys.stderr.write("%s: ERROR: [%s] %s\n" % (prog, id, str(e)))
+ error_count += 1
print("%s: %d error(s), %d file(s)" % (prog, error_count, file_count))