kivy import overwrites sys.stderr
Software Versions
- Python: 3.8.5
- OS: Ubuntu 20.04
- Kivy: git master
- Kivy installation method: pip install -e
Describe the bug
import kivy
Has a lot of side-effects, one of them is that sys.stderr is now kivy LogFile
Expected behavior Just importing the module must not have side effects like this in the operating environment (there are plenty of others too but let's keep them each in a separate issue)
To Reproduce
import kivy
Additional context
Also replacing the root logger is a sin, it's been discussed for example in #4113 and #4322, this messes up logging for every library that uses standard logging and is not aware of kivy (and why should they be, using the standard logger should just work) so any app using libraries like those suddenly loses all logs from them.
Anyway I'm going to look what I can do about these issues, PR will come later but progress can be seen at https://github.com/advian-oss/kivy/tree/logging
I have been working on this issue. I have an (insufficiently-tested yet) prototype that tidies up the stderr redirect to be cleaner.
In an ideal world, the redirect would be available to those who wanted it, but not get implemented by default upon import. However, I am worried about breaking existing apps if I remove it entirely.
Would it be satisfactory to allow override of the the default behaviour with an environment variable? (Or config?)
The proposal of using ENV/config variable sounds reasonable to maintain backwards compatibility while allowing integration of libraries that use the python standard logging systems correctly
Fixed about a year ago. Closing.