Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle possible race condition during directory create #37

Open
randomir opened this issue Oct 31, 2023 · 0 comments
Open

Handle possible race condition during directory create #37

randomir opened this issue Oct 31, 2023 · 0 comments

Comments

@randomir
Copy link
Member

For all directory lookup operations when create=True, this gets executed in _get_folder():

if create and not os.path.exists(final_path):
os.makedirs(final_path)

Since directory existence check and create are not one atomic operation, it's possible directory gets created (by another thread or process running the same code) between the check and the create. When that happens, the other thread/process fails with FileExistsError.

The solution here is to set exist_ok=True when calling os.makedirs. I.e. the create op should be idempotent here.

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

No branches or pull requests

1 participant