Skip to content

FIX: set exist_ok=True in os.makedirs() #120

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Dengda98
Copy link

replaces a non-atomic pattern for directory creation:

if not os.path.exists(dirname):
    os.makedirs(dirname)

with the safer:

os.makedirs(dirname, exist_ok=True)

In the parallel state (merged in #110 ), the original pattern is prone to race conditions: two processes may check for directory existence and both attempt to create it at the same time, will case FileExistsError. Using exist_ok=True makes directory creation atomic and thread-safe.

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.

2 participants