about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-03-25 14:41:47 -0500
committerFrederick Muriuki Muriithi2025-03-25 14:41:47 -0500
commit876c72c711905e2057fe8e2351a0bd458965e13a (patch)
treee00fcea33c25c8080308a53a651a8c3d3db258d8
parent10588aefeb4516fc0bcf3e25e0d8c27f548ee1a3 (diff)
downloadgn-libs-876c72c711905e2057fe8e2351a0bd458965e13a.tar.gz
Merge the 'with's to reduce indentation.
-rw-r--r--gn_libs/jobs/launcher.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/gn_libs/jobs/launcher.py b/gn_libs/jobs/launcher.py
index 10a24b1..0b45a34 100644
--- a/gn_libs/jobs/launcher.py
+++ b/gn_libs/jobs/launcher.py
@@ -18,23 +18,20 @@ def run_job(conn, job, outputs_directory: Path):
     jobs.update_metadata(conn, job_id, "stdout-file", str(stdout_file))
     jobs.update_metadata(conn, job_id, "stderr-file", str(stderr_file))
     try:
-        with (# TODO: Add the output streams' files to job metadata
-                stdout_file.open(mode="w") as outfile,
-                stderr_file.open(mode="w") as errfile,
-                subprocess.Popen(
-                    shlex.split(job["command"]),
-                    encoding="utf-8",
-                    stdout=outfile,
-                    stderr=errfile) as process):
-            with (stdout_file.open(mode="r") as stdout_output,
-                  stderr_file.open(mode="r") as stderr_output):
-                while process.poll() is None:
-                    jobs.update_metadata(conn, job_id, "status", "running")
-                    jobs.push_to_stream(
-                        conn, job_id, "stdout", stdout_output.read())
-                    jobs.push_to_stream(
-                        conn, job_id, "stderr", stderr_output.read())
-                    time.sleep(1)
+        with (stdout_file.open(mode="w") as outfile,
+              stderr_file.open(mode="w") as errfile,
+              stdout_file.open(mode="r") as stdout_in,
+              stderr_file.open(mode="r") as stderr_in,
+              subprocess.Popen(
+                  shlex.split(job["command"]),
+                  encoding="utf-8",
+                  stdout=outfile,
+                  stderr=errfile) as process):
+            while process.poll() is None:
+                jobs.update_metadata(conn, job_id, "status", "running")
+                jobs.push_to_stream(conn, job_id, "stdout", stdout_in.read())
+                jobs.push_to_stream(conn, job_id, "stderr", stderr_in.read())
+                time.sleep(1)
     except:
         jobs.update_metadata(conn, job_id, "status", "error")
         jobs.push_to_stream(conn, job_id, "stderr", traceback.format_exc())