Skip to content

Commit

Permalink
Add Ctrl-C handling to NED19 script.
Browse files Browse the repository at this point in the history
  • Loading branch information
akirmse committed Mar 10, 2024
1 parent 73e55af commit dd201b8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/run_ned19_prominence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import os
import re
import requests
import signal
import subprocess

from interrupt import handle_ctrl_c, init_pool
from multiprocessing import Pool
from zipfile import ZipFile

Expand All @@ -29,6 +31,7 @@ def fractionalDegree(degree: float) -> int:
excess = abs(degree - int(degree))
return int(100 * excess)

@handle_ctrl_c
def process_tile(args):
(lat, lng, tile_dir, contents) = args
lat_str = "%02dx%02d" % (abs(int(lat)), fractionalDegree(lat))
Expand Down Expand Up @@ -100,7 +103,8 @@ def main():
contents = requests.get(CONTENTS_URL).content.decode("utf-8")

# Run tile downloads in parallel because they're slow
pool = Pool(args.threads)
signal.signal(signal.SIGINT, signal.SIG_IGN)
pool = Pool(args.threads, initializer=init_pool)

process_args = []

Expand All @@ -115,7 +119,11 @@ def main():
lng += tile_size
lat += tile_size

pool.map(process_tile, process_args)
results = pool.map(process_tile, process_args)
if any(map(lambda x: isinstance(x, KeyboardInterrupt), results)):
print('Ctrl-C was entered.')
exit(1)

pool.close()
pool.join()

Expand Down

0 comments on commit dd201b8

Please sign in to comment.