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

makedirs bug when multiprocessing #310

Closed
simonm3 opened this issue Jul 15, 2019 · 3 comments
Closed

makedirs bug when multiprocessing #310

simonm3 opened this issue Jul 15, 2019 · 3 comments

Comments

@simonm3
Copy link

simonm3 commented Jul 15, 2019

I have multiple processes writing different files to the same folder. To ensure the folder hierarchy exists I call makedirs(recreate=True) before I create the files. Sometimes this fails saying folder already exists. This is because of race condition where another process created it after the check.

The pyfilesystem code in base/makedirs has thread lock which stops this happening in threads. It also has a try except to ignore the exception for the lowest subfolder. However this should be around the creation of parent folders too:

            dir_paths = tools.get_intermediate_dirs(self, path)
            for dir_path in dir_paths:
                self.makedir(dir_path, permissions=permissions)
            try:
                self.makedir(path)
            except errors.DirectoryExists:
                if not recreate:
                    raise
@simonm3
Copy link
Author

simonm3 commented Jul 17, 2019

Like this....also the code is missing a permissions parameter in the second call to makedir.

def makedirs(
    self,
    path,  # type: Text
    permissions=None,  # type: Optional[Permissions]
    recreate=False,  # type: bool
    ):
    self.check()
    with self._lock:
        dir_paths = tools.get_intermediate_dirs(self, path)
        for dir_path in dir_paths:
            try:
                self.makedir(dir_path, permissions=permissions)
            except errors.DirectoryExists:
                if not recreate:
                    raise
        try:
            self.makedir(path, permissions=permissions)
        except errors.DirectoryExists:
            if not recreate:
                raise
        return self.opendir(path)

@willmcgugan
Copy link
Member

That looks sensible. Would you mind submitting a PR?

@willmcgugan willmcgugan mentioned this issue Jul 28, 2019
9 tasks
@willmcgugan
Copy link
Member

Fixed in v2.4.9

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

2 participants