From 9692c76026fcc9f0938ca8253155c8f2c24ef108 Mon Sep 17 00:00:00 2001
From: "Ian Grant (aider)" <ian.conway.grant@gmail.com>
Date: Fri, 16 May 2025 18:57:41 -0400
Subject: [PATCH] fix: handle KeyboardInterrupt during job submission

---
 maap_utils/JobManager.py | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/maap_utils/JobManager.py b/maap_utils/JobManager.py
index ed82616..460778a 100644
--- a/maap_utils/JobManager.py
+++ b/maap_utils/JobManager.py
@@ -43,23 +43,28 @@ class JobManager:
         )
 
         tqdm.write("Submitting jobs")
-        for job_kwargs in tqdm(
-            self.job_kwargs_list[: self.config.job_limit],
-            total=total_jobs,
-            desc="",
-        ):
-            try:
-                job = Job(job_kwargs)
-                job.submit()
-                self.ledger.add_job(job)
-                job_batch_counter += 1
-            except Exception as e:
-                logging.error(f"Error submitting job: {e}")
-                continue
-
-            if job_batch_counter == job_batch_size:
-                time.sleep(job_submit_delay)
-                job_batch_counter = 0
+        try:
+            for job_kwargs in tqdm(
+                self.job_kwargs_list[: self.config.job_limit],
+                total=total_jobs,
+                desc="",
+            ):
+                try:
+                    job = Job(job_kwargs)
+                    job.submit()
+                    self.ledger.add_job(job)
+                    job_batch_counter += 1
+                except Exception as e:
+                    logging.error(f"Error submitting job: {e}")
+                    continue
+
+                if job_batch_counter == job_batch_size:
+                    time.sleep(job_submit_delay)
+                    job_batch_counter = 0
+        except KeyboardInterrupt:
+            logging.info("Submission interrupted by user")
+            self.exit_gracefully()
+            sys.exit(1)
 
         # Store output_dir and write job IDs
         self.output_dir = output_dir
-- 
GitLab