diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py
index b69de887ba3324f0f6ae3fc1e7c3764b4ba4968b..00fe25c787035ca00ce4fb9a890046786ff4463e 100644
--- a/pystencils/cpu/cpujit.py
+++ b/pystencils/cpu/cpujit.py
@@ -173,7 +173,8 @@ def read_config():
         config = recursive_dict_update(config, loaded_config)
     else:
         create_folder(config_path, True)
-        json.dump(config, open(config_path, 'w'), indent=4)
+        with open(config_path, 'w') as f:
+            json.dump(config, f, indent=4)
 
     if config['cache']['object_cache'] is not False:
         config['cache']['object_cache'] = os.path.expanduser(config['cache']['object_cache']).format(pid=os.getpid())