From 45d6930093412412a60989284ba8b4b54fdede52 Mon Sep 17 00:00:00 2001 From: SuslikV Date: Fri, 15 Jul 2022 13:03:28 +0200 Subject: [PATCH] Call the getctime() in a bit safer way Uses try..catch block inside the os.path.isfile() to skip inaccessible objects before calling getctime(). Uses short-circuit logic to cut null-path first. --- AdditionalReplays.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/AdditionalReplays.py b/AdditionalReplays.py index f6299fd..e9201bc 100644 --- a/AdditionalReplays.py +++ b/AdditionalReplays.py @@ -117,27 +117,20 @@ def install_needed(prop, props): def save_and_get_last_replay(): timestamp = time.time() obs.obs_frontend_replay_buffer_save() - path = get_last_replay() - if path is None: - sleep(2) - path = get_last_replay() - if not os.path.exists(path): - sleep(2) + + # Try to get the file timestamp 20 times, only then give up, interval 1 sec + for i in range(20): path = get_last_replay() - for i in range(20): - file_timestamp = os.path.getctime(path) - if file_timestamp < timestamp: - sleep(1) - path = get_last_replay() - else: - break - - file_timestamp = os.path.getctime(path) - if file_timestamp < timestamp: - return None - else: - return path - + if path and os.path.isfile(path): + file_timestamp = os.path.getctime(path) + if file_timestamp < timestamp: + path = None + else: + break + sleep(1) + + return path + def get_last_replay(): replay_buffer = obs.obs_frontend_get_replay_buffer_output() cd = obs.calldata_create()