From 3ef9bff42dc05f613a67bb9da449d3a6510da9f6 Mon Sep 17 00:00:00 2001 From: "yexuan.li" Date: Fri, 19 Nov 2021 17:04:50 +0800 Subject: [PATCH] fix(utility): fix the FileExistsError when using cache with multiprocess 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: https://github.com/Graviti-AI/tensorbay-python-sdk/pull/1113 --- tensorbay/utility/file.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tensorbay/utility/file.py b/tensorbay/utility/file.py index c00e04605..dc6960006 100644 --- a/tensorbay/utility/file.py +++ b/tensorbay/utility/file.py @@ -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: