From 009c40e08a1ea2db8efad4d78f3ba693c2e9059c Mon Sep 17 00:00:00 2001 From: Jake Pullen Date: Mon, 8 Dec 2025 19:14:02 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Quick=20Exit=20on=20keybo?= =?UTF-8?q?ard=20interrupt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- modules/batch_nimrod.py | 13 +++++++++---- modules/generate_timeseries.py | 27 ++++++++++++++++----------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 8144d4a..07c8c0f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,10 +9,13 @@ wheels/ # Virtual environments .venv +dat_other/* dat_files/* asc_files/* csv_files/* combined_files/* zone_inputs/* -*.tar.gz \ No newline at end of file +*.tar.gz + +generate_test_data.py \ No newline at end of file diff --git a/modules/batch_nimrod.py b/modules/batch_nimrod.py index 81d0e97..e38ae50 100644 --- a/modules/batch_nimrod.py +++ b/modules/batch_nimrod.py @@ -72,8 +72,13 @@ class BatchNimrod: } completed_count = 0 - for future in concurrent.futures.as_completed(future_to_file): - completed_count += 1 - if completed_count % 10 == 0: - logging.info(f'processed {completed_count} out of {total_files} files') + try: + for future in concurrent.futures.as_completed(future_to_file): + completed_count += 1 + if completed_count % 10 == 0: + logging.info(f'processed {completed_count} out of {total_files} files') + except KeyboardInterrupt: + logging.warning("KeyboardInterrupt received. Cancelling pending tasks...") + executor.shutdown(wait=False, cancel_futures=True) + raise diff --git a/modules/generate_timeseries.py b/modules/generate_timeseries.py index 19d0c40..a771f83 100644 --- a/modules/generate_timeseries.py +++ b/modules/generate_timeseries.py @@ -152,17 +152,22 @@ class GenerateTimeseries: } completed_count = 0 - for future in concurrent.futures.as_completed(future_to_file): - file_results = future.result() - if file_results: - for res in file_results: - zone_id = res['zone_id'] - results[zone_id]['dates'].append(res['date']) - results[zone_id]['values'].append(res['value']) - - completed_count += 1 - if completed_count % 100 == 0: - print(f"Processed {completed_count}/{total_files} files") + try: + for future in concurrent.futures.as_completed(future_to_file): + file_results = future.result() + if file_results: + for res in file_results: + zone_id = res['zone_id'] + results[zone_id]['dates'].append(res['date']) + results[zone_id]['values'].append(res['value']) + + completed_count += 1 + if completed_count % 100 == 0: + print(f"Processed {completed_count}/{total_files} files") + except KeyboardInterrupt: + print("KeyboardInterrupt received. Cancelling pending tasks...") + executor.shutdown(wait=False, cancel_futures=True) + raise # Write CSVs for each location print("Writing CSV files...")