Skip to content

Commit

Permalink
Update on "Adding lock mechanism to prevent on_disk_cache downloading…
Browse files Browse the repository at this point in the history
… twice"


Fixes #144

[ghstack-poisoned]
  • Loading branch information
VitalyFedyunin committed May 18, 2022
1 parent 0a80ea4 commit c6a06d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/test_local_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def test_disk_cache_locks(self):
dp = dp.end_caching(mode="t", filepath_fn=_noop, timeout=120)
dp = FileOpener(dp)
dp = StreamReader(dp)
dl = DataLoader(dp, num_workers=10, multiprocessing_context="spawn", batch_size=1, collate_fn=_unbatch)
dl = DataLoader(dp, num_workers=5, multiprocessing_context="spawn", batch_size=1, collate_fn=_unbatch)
result = list(dl)
all_files = []
for (_, _, filenames) in os.walk(tmpdirname):
Expand Down
19 changes: 10 additions & 9 deletions torchdata/datapipes/iter/util/cacheholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,16 @@ def _find_promise_file(filename):


def _is_promise_pending(promise_filename):
try:
with portalocker.Lock(promise_filename, "r") as promise_fh:
data = promise_fh.read()
file_exists = len(data) > 0
except FileNotFoundError:
return False
except PermissionError:
return True
return file_exists
return os.path.exists(promise_filename)
# try:
# with portalocker.Lock(promise_filename, "r") as promise_fh:
# data = promise_fh.read()
# file_exists = len(data) > 0
# except FileNotFoundError:
# return False
# except PermissionError:
# return True
# return file_exists


def _wait_promise_fn(timeout, filename):
Expand Down

0 comments on commit c6a06d2

Please sign in to comment.