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