-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring and improvement: Config class is now a singleton #1307
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hauptsächlich Typos, eine inhaltliche Frage (zur Änderung an sshMaxArg.py
)
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
Co-authored-by: Michael Büker <emtiu@users.noreply.github.com>
I raise concerns that a singleton config does work correctly since I see
See eg. the code when the "Take snapshot" button is clicked: Lines 873 to 875 in b14a98f
and backintime/common/backintime.py Lines 48 to 80 in b14a98f
I personally would prefer if the |
I still vote for merge but understand and agree with some of your concerns. Most of the time the config file is just read. In that case it doesn't matter how often it is opened. In fact in the current situation before that PR dozens of And that is the intention of that singleton to bring up other problems that might resist in the code.
See above. This isn't a problem. GUI is mutli-threaded by definition. And I assume you mean mutli-processing where
I don't see a problem. The term "async" is missleading in the code. It is multi-processing because a complete new backintime instances (and its own python interpreter) is created via I see no problem if a sub-process need another config that it should use it. This doesn't effect the singleton. Because the Config instances only exists in the context of one specific backintime instances. When you call
I don't see a problem here. That function simply read a bool value from the config instance. That is a big problem of the whole code. To many parts of the code do handling direct the config object. That cause a lot of problems, bad code, etc. Also that BIT does call itself via
I strongly disagree because this would undermine the very objective of that PR and the singleton. The
No. Exceptions like this never need to be tested. That is what exceptions are for. This is not a returning error code. When someone is doing this the whole BIT thing need to stop. That is why there is an exception. A situation like this should never happen. |
We've agreed to stash this refactoring in its own branch first, while the main branch receives mainly bugfixes. |
The most important changes were made in
common/config.py
andcommon/test/generic.py
.As discussed the class
config.Config
now acts like a singleton. No matter that there are a lot of possible variants to implement the singleton design patter in Python I choose a pragmatic one, that is IMHO easy to understand for newbies, using less lines and is easy to maintain.config.Config()
config.Config.instance()
From an academic point of view this may not fulfill all aspects of the singleton pattern. But it prevents new contributors for misusing it.
I touched a lot of other files to use
config.Config.instance()
instead ofConfig()
. I also improved the unittests because most of them did create their ownConfig
instance (most of them viageneric.TestCaseCfg
base class). Now all unittest do destroy there instance if they have created that instance them selfs.PS: You have to squash before merge Sorry for the 13 commits. This PR was intended to have only one commit but I misused
git
.