diff options
author | Andy Grover <andy@groveronline.com> | 2018-03-14 22:59:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 22:59:02 -0700 |
commit | 4b494b6eb25fea71a7c536f8b6e16b3b6e0b83a4 (patch) | |
tree | b87f7665737fcd4001905335bc8de7d4fd688699 | |
parent | 445178051da1fe7a28bf1914d7e957ef9d0a290d (diff) | |
parent | 0fe285ff2592ae35e8238927979d7dfa1fa05ed8 (diff) | |
download | configshell-fb-4b494b6eb25fea71a7c536f8b6e16b3b6e0b83a4.tar.gz |
Merge pull request #43 from avagin/lock
Acquire a lock to a preference file before working with it
-rw-r--r-- | configshell/prefs.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/configshell/prefs.py b/configshell/prefs.py index 248cc1d..7faa1fe 100644 --- a/configshell/prefs.py +++ b/configshell/prefs.py @@ -16,6 +16,7 @@ under the License. ''' import six +import fcntl class Prefs(object): ''' @@ -128,6 +129,7 @@ class Prefs(object): if filename is not None: fsock = open(filename, 'wb') + fcntl.lockf(fsock, fcntl.LOCK_UN) try: six.moves.cPickle.dump(self._prefs, fsock, 2) finally: @@ -143,6 +145,7 @@ class Prefs(object): if filename is not None: fsock = open(filename, 'rb') + fcntl.lockf(fsock, fcntl.LOCK_SH) try: self._prefs = six.moves.cPickle.load(fsock) finally: |