diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py index 4da43010a44945920687a84db2f5fa3bb848b01c..dfb33e74b02ae31b2f1946ea194a1c28581e54a0 100644 --- a/pystencils/cpu/cpujit.py +++ b/pystencils/cpu/cpujit.py @@ -52,7 +52,7 @@ import subprocess import textwrap from collections import OrderedDict from sysconfig import get_paths -from tempfile import TemporaryDirectory +from tempfile import TemporaryDirectory, NamedTemporaryFile import numpy as np from appdirs import user_cache_dir, user_config_dir @@ -221,7 +221,9 @@ def read_config(): shutil.rmtree(config['cache']['object_cache'], ignore_errors=True) create_folder(config['cache']['object_cache'], False) - json.dump(config['compiler'], open(cache_status_file, 'w'), indent=4) + with NamedTemporaryFile('w', dir=os.path.dirname(cache_status_file), delete=False) as f: + json.dump(config['compiler'], f, indent=4) + os.replace(f.name, cache_status_file) if config['compiler']['os'] == 'windows': from pystencils.cpu.msvc_detection import get_environment