From b0774679273dfb92c3a7ca18f6b4fc6d9ec2fa16 Mon Sep 17 00:00:00 2001 From: Valerio Cosentino Date: Tue, 17 Sep 2019 16:26:06 +0200 Subject: [PATCH] [config] Live reload of setup.cfg This code allows to reload the setup.cfg everytime the method `get_conf` in the class `Config` is called. Signed-off-by: Valerio Cosentino --- sirmordred/config.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sirmordred/config.py b/sirmordred/config.py index 86e89f65..421a9d37 100644 --- a/sirmordred/config.py +++ b/sirmordred/config.py @@ -22,6 +22,7 @@ import configparser import logging +from threading import Lock from sirmordred._version import __version__ @@ -41,6 +42,8 @@ class Config(): """Class aimed to manage sirmordred configuration""" + config_lock = Lock() + def __init__(self, conf_file, conf_list=[]): """Initialize object. @@ -654,8 +657,11 @@ def create_config_file(cls, file_path): parser.write(f) def get_conf(self): - # TODO: Return a deepcopy to avoid uncontrolled changes in config? - return self.conf + """Reload configuration files""" + + with self.config_lock: + self.__read_conf_files() + return self.conf def set_param(self, section, param, value): """ Change a param in the config """