Skip to content

Commit

Permalink
Bug Fix: Fixed FileExistsError (#1187)
Browse files Browse the repository at this point in the history
Summary:
Fixed bug where multiple workers try to write to the same folder that doesn't exist yet, it causes a FileExistsError because a different work already created the directory structure.

Fixes #{1186}

### Changes

- Removed if statement which checks if `dirname` exists and modified to use built-in `os.makedirs` feature for checking if `dirname` exists

Pull Request resolved: #1187

Reviewed By: ejguan

Differential Revision: D55278447

Pulled By: gokulavasan

fbshipit-source-id: 50088457cce3d0b5c62529b5290d45f31ce0144f
  • Loading branch information
knoriy authored and facebook-github-bot committed Mar 25, 2024
1 parent ead14ee commit 4725a01
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions torchdata/datapipes/iter/util/cacheholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ def _cache_check_fn(data, filepath_fn, hash_dict, hash_type, extra_check_fn, cac
if not cached_file_exists:
promise_filepath = _promise_filename(filepath, cache_uuid)
dirname = os.path.dirname(promise_filepath)
if not os.path.exists(dirname):
os.makedirs(dirname)
os.makedirs(dirname, exist_ok=True)

with portalocker.Lock(promise_filepath, "a+", flags=portalocker.LockFlags.EXCLUSIVE) as promise_fh:
promise_fh.seek(0)
Expand Down

0 comments on commit 4725a01

Please sign in to comment.