[Python] Replace os.path.exists with try...except...else (#4784)
authorhlu1 <14827759+hlu1@users.noreply.github.com>
Wed, 29 Jan 2020 01:58:36 +0000 (17:58 -0800)
committerGitHub <noreply@github.com>
Wed, 29 Jan 2020 01:58:36 +0000 (09:58 +0800)
python/tvm/contrib/pickle_memoize.py

index 5c16419..6e72aba 100644 (file)
@@ -40,8 +40,12 @@ class Cache(object):
     cache_by_key = {}
     def __init__(self, key, save_at_exit):
         cache_dir = ".pkl_memoize_py{0}".format(sys.version_info[0])
-        if not os.path.exists(cache_dir):
+        try:
             os.mkdir(cache_dir)
+        except FileExistsError:
+            pass
+        else:
+            self.cache = {}
         self.path = os.path.join(cache_dir, key)
         if os.path.exists(self.path):
             try: