From 16ddb2bdeeb773284560b06517b3735f540709b1 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 5 Jul 2024 18:18:35 -0400 Subject: [PATCH] Wrap command runs in a finally block Ensures that cleanup happens even if something else weird happens, which tends to happen to my systems a lot leaving stuck processes. --- rffmpeg | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/rffmpeg b/rffmpeg index 07f65f5..b459860 100755 --- a/rffmpeg +++ b/rffmpeg @@ -557,19 +557,23 @@ def run_ffmpeg(config, ffmpeg_args): target_hid, target_hostname, target_servername = get_target_host(config) - if not target_hostname or target_hostname == "localhost": - ret = run_local_ffmpeg(config, target_hid, ffmpeg_args) - else: - ret = run_remote_ffmpeg( - config, target_hid, target_hostname, target_servername, ffmpeg_args - ) - - cleanup() - if ret.returncode == 0: - log.info(f"Finished rffmpeg with return code {ret.returncode}") - else: - log.error(f"Finished rffmpeg with return code {ret.returncode}") - exit(ret.returncode) + try: + returncode = 200 + if not target_hostname or target_hostname == "localhost": + ret = run_local_ffmpeg(config, ffmpeg_args) + returncode = ret.returncode + else: + ret = run_remote_ffmpeg( + config, target_hid, target_hostname, target_servername, ffmpeg_args + ) + returncode = ret.returncode + finally: + cleanup() + if returncode == 0: + log.info(f"Finished rffmpeg with return code {ret.returncode}") + else: + log.error(f"Finished rffmpeg with return code {ret.returncode}") + exit(returncode) def run_control(config):