Skip to content

Conversation

@SuslikV
Copy link

@SuslikV SuslikV commented Jul 15, 2022

This is attempt to fix the issue reported on the OBS forum:
https://obsproject.com/forum/threads/help-python-script-obs-help-needed-additional-replay-buffer.157771/

It is not safe to call the os.path.getctime(path) if path is None.

Edit: I made few mistakes too, I hope it is fixed now
New code block will look like this:

def save_and_get_last_replay():
    timestamp = time.time()
    obs.obs_frontend_replay_buffer_save()

    # Try to get the file timestamp 20 times, only then give up, interval 1 sec
    for i in range(20):
        path = get_last_replay()
        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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant