@@ -300,7 +300,8 @@ def _lock_file_path(self):
300
300
memo_cache = {},
301
301
persist_path = os .path .join (
302
302
tempfile .gettempdir (),
303
- 'qn-py-sdk-regions-cache.jsonl'
303
+ 'qn-py-sdk' ,
304
+ 'regions-cache.jsonl'
304
305
),
305
306
last_shrink_at = datetime .datetime .fromtimestamp (0 ),
306
307
shrink_interval = datetime .timedelta (days = 1 ),
@@ -520,8 +521,23 @@ def __init__(
520
521
persist_path = kwargs .get ('persist_path' , None )
521
522
last_shrink_at = datetime .datetime .fromtimestamp (0 )
522
523
if persist_path is None :
523
- persist_path = _global_cache_scope .persist_path
524
- last_shrink_at = _global_cache_scope .last_shrink_at
524
+ cache_dir = os .path .dirname (_global_cache_scope .persist_path )
525
+ try :
526
+ # make sure the cache dir is available for all users.
527
+ # we can not use the '/tmp' dir directly on linux,
528
+ # because the permission is 0o1777
529
+ if os .path .exists (cache_dir ):
530
+ # os.makedirs have no exists_ok parameter in python 2.7
531
+ os .makedirs (cache_dir , mode = 0o777 )
532
+ persist_path = _global_cache_scope .persist_path
533
+ last_shrink_at = _global_cache_scope .last_shrink_at
534
+ except Exception as err :
535
+ if "File exists" in str (err ):
536
+ persist_path = _global_cache_scope .persist_path
537
+ last_shrink_at = _global_cache_scope .last_shrink_at
538
+ else :
539
+ logging .warning (
540
+ 'failed to create cache dir %s. error: %s' , cache_dir , err )
525
541
526
542
shrink_interval = kwargs .get ('shrink_interval' , None )
527
543
if shrink_interval is None :
0 commit comments