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,6 +279,7 @@ 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:
try:
proc = subprocess.run( proc = subprocess.run(
command, command,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
@ -287,6 +288,11 @@ def run_and_log_handbrake(dvd: Dvd, command) -> bool:
) )
if proc.returncode != 0: if proc.returncode != 0:
return False 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): if check_handbrake_log_for_error(dvd):
return False return False
@ -309,6 +315,7 @@ 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:
try:
proc = subprocess.run( proc = subprocess.run(
[ [
"nice", "nice",
@ -327,6 +334,11 @@ def find_series_titles(dvd: Dvd):
stderr=log_file, stderr=log_file,
timeout=TRANSCODE_TIMEOUT_SECONDS, 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