Skip to content

Commit

Permalink
fix(utility): fix the FileExistsError when using cache with multiprocess
Browse files Browse the repository at this point in the history
When using cache with multiprocess, the result will not necessarily stay
true after asserting `os.path.exists(cache_path) == True`.
Add `exist_ok` when calling `os.makedirs` to fix this problem.

PR Closed: #1113
  • Loading branch information
Lee-000 authored and linjiX committed Dec 1, 2021
1 parent 8a63c64 commit 3ef9bff
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions tensorbay/utility/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ def open(self) -> Union[HTTPResponse, BufferedReader]:

if not os.path.exists(cache_path):
dirname = os.path.dirname(cache_path)
if not os.path.exists(dirname):
os.makedirs(dirname)
os.makedirs(dirname, exist_ok=True)

with self._urlopen() as fp:
with open(cache_path, "wb") as cache:
Expand Down

0 comments on commit 3ef9bff

Please sign in to comment.