88# Avoid checking the name of type annotations at run time
99from __future__ import annotations
1010
11+ import contextlib
1112import copy
1213import ctypes
1314import ctypes .util
2223from functools import lru_cache
2324from typing import TYPE_CHECKING
2425
25- import cpuinfo
2626import numpy as np
2727
2828import blosc2
@@ -1152,13 +1152,13 @@ def linux_cache_size(cache_level: int, default_size: int) -> int:
11521152
11531153
11541154def write_cached_cpu_info (cpu_info_dict : dict [str , any ]) -> None :
1155- with open (Path .home () / ' .blosc2-cpuinfo.json' , 'w' ) as f :
1155+ with open (pathlib . Path .home () / " .blosc2-cpuinfo.json" , "w" ) as f :
11561156 json .dump (cpu_info_dict , f , indent = 4 )
11571157
11581158
11591159def read_cached_cpu_info () -> dict :
11601160 try :
1161- with open (Path .home () / ' .blosc2-cpuinfo.json' , 'r' ) as f :
1161+ with open (pathlib . Path .home () / " .blosc2-cpuinfo.json" ) as f :
11621162 return json .load (f )
11631163 except (FileNotFoundError , json .JSONDecodeError ):
11641164 return {}
@@ -1175,12 +1175,9 @@ def get_cpu_info() -> dict:
11751175 except ImportError :
11761176 return {}
11771177 cpu_info_dict = cpuinfo .get_cpu_info ()
1178- try :
1178+ with contextlib .suppress (OSError ):
1179+ # In case cpu info cannot be stored, will need to be recomputed in the next process
11791180 write_cached_cpu_info (cpu_info_dict )
1180- except IOError :
1181- # cpu info cannot be stored.
1182- # will need to be recomputed in the next process
1183- pass
11841181 return cpu_info_dict
11851182
11861183
0 commit comments