+ # written (if another read/write of a more recent configuration
+ # is interleaved). The final atomic rename is to keep this
+ # transactionally isolated from the above cache read. If we fail to
+ # acquire the lock, just try to load the master configuration.
+ import yaml
+ try: loader = yaml.CSafeLoader
+ except: loader = yaml.SafeLoader
+ try:
+ @with_lock_file(lock_file)
+ def refresh_cache():
+ ns.cfg = with_closing(file(src_path)) (
+ lambda f: yaml.load(f, loader))
+ try: with_closing(file(cache_path + '.tmp', 'w')) (
+ lambda f: f.write(json.write(ns.cfg)))
+ except: pass # silent failure
+ else: os.rename(cache_path + '.tmp', cache_path)
+ except IOError: