add locks to config and storage

This commit is contained in:
ThomasV 2013-09-29 18:33:54 +02:00
parent 44edb4e2bb
commit e82653f454
2 changed files with 19 additions and 18 deletions

View File

@ -1,12 +1,10 @@
import json, ast import json
import os, ast import ast
import threading
import os
from util import user_dir, print_error from util import user_dir, print_error
from version import ELECTRUM_VERSION, SEED_VERSION
class SimpleConfig: class SimpleConfig:
@ -17,6 +15,7 @@ user configurations from electrum.conf into separate dictionaries within
a SimpleConfig instance then reads the wallet file. a SimpleConfig instance then reads the wallet file.
""" """
def __init__(self, options={}): def __init__(self, options={}):
self.lock = threading.Lock()
# system conf, readonly # system conf, readonly
self.system_config = {} self.system_config = {}
@ -65,8 +64,11 @@ a SimpleConfig instance then reads the wallet file.
print "Warning: not changing '%s' because it was set in the system configuration"%key print "Warning: not changing '%s' because it was set in the system configuration"%key
else: else:
self.user_config[key] = value
if save: self.save_user_config() with self.lock:
self.user_config[key] = value
if save:
self.save_user_config()

View File

@ -68,6 +68,7 @@ from version import ELECTRUM_VERSION, SEED_VERSION
class WalletStorage: class WalletStorage:
def __init__(self, config): def __init__(self, config):
self.lock = threading.Lock()
self.data = {} self.data = {}
self.file_exists = False self.file_exists = False
self.init_path(config) self.init_path(config)
@ -110,15 +111,13 @@ class WalletStorage:
def put(self, key, value, save = True): def put(self, key, value, save = True):
if self.data.get(key) is not None: with self.lock:
self.data[key] = value if value is not None:
else: self.data[key] = value
# add key to wallet config else:
self.data[key] = value self.data.pop[key]
if save:
if save: self.write()
self.write()
def write(self): def write(self):
s = repr(self.data) s = repr(self.data)