Loguru stops TKinter Application from Exiting
Hi!
First of all - i love loguru, it's a great tool and until now I had zero problem using it. Currently I run into a problem however, i have a fairly complex application that used loguru in multiple places and also multiple threads. In the TKinter UI I want to show the log (at >= Info level). Threfore i create a seperate handle:
self.logger_handler = logger.add(self.add_log_to_gui, colorize=False, level="INFO")
This works fine, until i try to use my _on_closing function
def _on_closing(self):
# stop everything
self._middleware.stop()
logger.remove(self.logger_handler)
logger.success("closing application")
# destroy main frame
self.destroy()
self.quit()
The call of the closing function happens when the "X" button in the window is clicked, an that is done by the following code:
self.protocol("WM_DELETE_WINDOW", self._on_closing)
The last command in middleware.stop is also executed (which is another logging command) and than nothing more happens. If I remove adding of the logging handler (as shown before) defined for the UI everything works fine and the application closes. I'm not quite sure if the problem is a bug in loguru or if it's just me doing something wrong - if someone has an idea, I would appreciate that.
Thanks, Dominik
Hi. :)
Would you be able to share a minimal reproducible example please?
It seems Loguru is encountered a dead lock. This can happens if the logger is used inside a __del__ method or a signal handler. However, I don't know exactly what happens in your case with Tkinter.
You can also try to install dev version of Loguru which contains a safety check avoiding deadlock:
pip install git+https://github.com/Delgan/loguru@11951c76d5b2a1bc5809b73b8fd41e804e23a6cc