From 21e691dce4af7f5fef9dc3549778809d533e155e Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Tue, 10 Apr 2018 17:53:23 +0200 Subject: [PATCH] config: Avoid race conditions --- weboob/tools/config/extra.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/weboob/tools/config/extra.py b/weboob/tools/config/extra.py index 56d9a49c55..82978a9926 100644 --- a/weboob/tools/config/extra.py +++ b/weboob/tools/config/extra.py @@ -38,17 +38,24 @@ class ForkingConfig(object): """ process = None + def __init__(self, *args, **kwargs): + self.lock = multiprocessing.RLock() + super(ForkingConfig, self).__init__(*args, **kwargs) + def join(self): - if self.process: - self.process.join() + with self.lock: + if self.process: + self.process.join() + self.process = None def save(self): # if a save is already in progress, wait for it to finish self.join() parent_save = super(ForkingConfig, self).save - self.process = multiprocessing.Process(target=parent_save, name=u'save %s' % self.path) - self.process.start() + with self.lock: + self.process = multiprocessing.Process(target=parent_save, name=u'save %s' % self.path) + self.process.start() def __exit__(self, t, v, tb): self.join() -- GitLab