From: Ben Steffen Date: Tue, 26 Nov 2019 19:49:54 +0000 (-0500) Subject: Don't use contextlib where it is no longer necessary X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-base.git/commitdiff_plain/ba6c72bf6fc6ec7d54fcbcfdcbf0837aab3e7fc1?ds=sidebyside Don't use contextlib where it is no longer necessary --- diff --git a/python/invirt/config.py b/python/invirt/config.py index 03b6a2d..245464b 100644 --- a/python/invirt/config.py +++ b/python/invirt/config.py @@ -1,7 +1,6 @@ import json from invirt.common import * import os -from contextlib import closing import yaml import re @@ -59,7 +58,7 @@ def list_files(): def load_master(): config = dict() for filename in list_files(): - with closing(open(filename)) as f: + with open(filename) as f: augment(config, yaml.load(f, loader)) return config @@ -112,7 +111,7 @@ def load(force_refresh = False): # lock with other concurrent reads). This isolation is accomplished # using an atomic filesystem rename in the refreshing stage. try: - with closing(open(cache_path)) as f: + with open(cache_path) as f: ns.cfg = json.read(f.read()) except: do_refresh = True @@ -127,7 +126,7 @@ def load(force_refresh = False): with lock_file(lock_path): ns.cfg = load_master() try: - with closing(open(cache_path + '.tmp', 'w')) as f: + with open(cache_path + '.tmp', 'w') as f: f.write(json.write(ns.cfg)) except: pass # silent failure else: os.rename(cache_path + '.tmp', cache_path)