8
8
# Avoid checking the name of type annotations at run time
9
9
from __future__ import annotations
10
10
11
+ import contextlib
11
12
import copy
12
13
import ctypes
13
14
import ctypes .util
22
23
from functools import lru_cache
23
24
from typing import TYPE_CHECKING
24
25
25
- import cpuinfo
26
26
import numpy as np
27
27
28
28
import blosc2
@@ -1152,13 +1152,13 @@ def linux_cache_size(cache_level: int, default_size: int) -> int:
1152
1152
1153
1153
1154
1154
def 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 :
1156
1156
json .dump (cpu_info_dict , f , indent = 4 )
1157
1157
1158
1158
1159
1159
def read_cached_cpu_info () -> dict :
1160
1160
try :
1161
- with open (Path .home () / ' .blosc2-cpuinfo.json' , 'r' ) as f :
1161
+ with open (pathlib . Path .home () / " .blosc2-cpuinfo.json" ) as f :
1162
1162
return json .load (f )
1163
1163
except (FileNotFoundError , json .JSONDecodeError ):
1164
1164
return {}
@@ -1175,12 +1175,9 @@ def get_cpu_info() -> dict:
1175
1175
except ImportError :
1176
1176
return {}
1177
1177
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
1179
1180
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
1184
1181
return cpu_info_dict
1185
1182
1186
1183
0 commit comments