# HG changeset patch # User Julien Cristau # Date 1382111591 -7200 # Node ID 70f6b183085a64a22fb2e7fc2dce930a6f0e0bb8 # Parent 722635e530a0bf50271779579d0ffccfdadbf0e9 [devtools] write db config through a temporary file Avoids other test processes reading partially written config and exploding in pickle.loads. There are still concurrency issues, presumably with the database itself. Something for another friday. diff -r 722635e530a0 -r 70f6b183085a devtools/__init__.py --- a/devtools/__init__.py Wed Nov 13 12:39:30 2013 +0100 +++ b/devtools/__init__.py Fri Oct 18 17:53:11 2013 +0200 @@ -26,6 +26,7 @@ import pickle import glob import warnings +import tempfile from hashlib import sha1 # pylint: disable=E0611 from datetime import timedelta from os.path import (abspath, join, exists, split, isabs, isdir) @@ -328,8 +329,9 @@ # XXX we dump a dict of the config # This is an experimental to help config dependant setup (like BFSS) to # be propertly restored - with open(config_path, 'wb') as conf_file: + with tempfile.NamedTemporaryFile(dir=os.path.dirname(config_path), delete=False) as conf_file: conf_file.write(pickle.dumps(dict(self.config))) + os.rename(conf_file.name, config_path) self.db_cache[self.db_cache_key(db_id)] = (backup_data, config_path) def _backup_database(self, db_id):