-
Notifications
You must be signed in to change notification settings - Fork 4
/
cache_manager.py
41 lines (30 loc) · 1.04 KB
/
cache_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Helpers for the RWTH-i6 cache manager
https://github.com/rwth-i6/cache-manager
"""
import os
from subprocess import check_output, CalledProcessError
def cf(filename: str) -> str:
"""Cache manager"""
if filename in _cf_cache:
return _cf_cache[filename]
debug_mode = _get_debug_mode()
hostname = _get_hostname()
if debug_mode or not hostname.startswith("cluster-cn-"):
print("use local file: %s" % filename)
return filename # for debugging
try:
cached_fn = check_output(["cf", filename]).strip().decode("utf8")
except CalledProcessError:
print("Cache manager: Error occurred, using local file")
return filename
assert os.path.exists(cached_fn)
_cf_cache[filename] = cached_fn
return cached_fn
_cf_cache = {}
def _get_debug_mode() -> bool:
from returnn.config import get_global_config
config = get_global_config()
return config.typed_dict.get("debug_mode", False)
def _get_hostname() -> str:
return check_output(["hostname"]).strip().decode("utf8")