Add timeout error handling

This commit is contained in:
Julian Mutter 2023-10-06 16:02:16 +02:00
parent a7bc9c6257
commit 5790b9134e

View File

@ -279,13 +279,19 @@ def transcode_episode(dvd: Dvd, season, episode, title_number):
# Returns success # Returns success
def run_and_log_handbrake(dvd: Dvd, command) -> bool: def run_and_log_handbrake(dvd: Dvd, command) -> bool:
with open(dvd.log_file, "a") as log_file: with open(dvd.log_file, "a") as log_file:
proc = subprocess.run( try:
command, proc = subprocess.run(
stderr=subprocess.STDOUT, command,
stdout=log_file, stderr=subprocess.STDOUT,
timeout=TRANSCODE_TIMEOUT_SECONDS, stdout=log_file,
) timeout=TRANSCODE_TIMEOUT_SECONDS,
if proc.returncode != 0: )
if proc.returncode != 0:
return False
except subprocess.TimeoutExpired:
log_file.write(
f"Transcoding timeout of {TRANSCODE_TIMEOUT_SECONDS}s reached!"
)
return False return False
if check_handbrake_log_for_error(dvd): if check_handbrake_log_for_error(dvd):
@ -309,24 +315,30 @@ def find_series_titles(dvd: Dvd):
return read_titles_from_titles_file(dvd) return read_titles_from_titles_file(dvd)
with open(dvd.log_file, "w") as log_file: with open(dvd.log_file, "w") as log_file:
proc = subprocess.run( try:
[ proc = subprocess.run(
"nice", [
"-n", "nice",
str(HANDBRAKE_PROCESS_NICE_LEVEL), "-n",
"HandBrakeCLI", str(HANDBRAKE_PROCESS_NICE_LEVEL),
"--input", "HandBrakeCLI",
dvd.dvd_path, "--input",
"-t", dvd.dvd_path,
"0", "-t",
"--min-duration", "0",
str(MIN_EPISODES_DURATION_SECONDS), "--min-duration",
"--json", str(MIN_EPISODES_DURATION_SECONDS),
], "--json",
stdout=subprocess.PIPE, ],
stderr=log_file, stdout=subprocess.PIPE,
timeout=TRANSCODE_TIMEOUT_SECONDS, stderr=log_file,
) timeout=TRANSCODE_TIMEOUT_SECONDS,
)
except subprocess.TimeoutExpired:
log_file.write(
f"Transcoding timeout of {TRANSCODE_TIMEOUT_SECONDS}s reached!"
)
return None
if proc.returncode != 0: if proc.returncode != 0:
return None return None