Skip to content

Commit

Permalink
write config to tempfile and rename to avoid race.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenBickerton committed Mar 3, 2015
1 parent 54dad1f commit 6e44b4e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/lsst/pex/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import os
import io
import traceback
import sys
import math
import collections
import copy
import re
import tempfile

from .comparison import *

Expand Down Expand Up @@ -615,8 +617,10 @@ def save(self, filename, root="root"):
@param root [in] name to use for the root config variable
If not "root", must match what is used in load())
"""
with open(filename, 'w') as outfile:
d = os.path.split(filename)[0]
with tempfile.NamedTemporaryFile(delete=False, dir=d) as outfile:
self.saveToStream(outfile, root)
os.rename(outfile.name, filename)

def saveToStream(self, outfile, root="root"):
"""
Expand Down

0 comments on commit 6e44b4e

Please sign in to comment.