Skip to content

Commit

Permalink
fix: infinite logging on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
F33RNI committed Dec 25, 2023
1 parent 4399882 commit b1d34cc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
22 changes: 18 additions & 4 deletions GUIHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,17 +792,30 @@ def closeEvent(self, event) -> None:

# No file -> Exit without asking
else:
# Accept event
logging.info("Closing GUI")

# Stop logging handler
self._logging_queue.put(None)
self._logging_handler.remove_external_queue(self._logging_queue)

# Accept event
event.accept()


class GUIHandler:
def __init__(self, config_manager: ConfigManager.ConfigManager):
self._config_manager = config_manager

def start_gui(self, logging_handler: LoggingHandler.LoggingHandler, backupper: Backupper.Backupper) -> None:
"""Starts GUI (blocking)"""
def start_gui(self, logging_handler: LoggingHandler.LoggingHandler, backupper: Backupper.Backupper) -> int:
"""Starts GUI (blocking)
Args:
logging_handler (LoggingHandler.LoggingHandler): LoggingHandler class object
backupper (Backupper.Backupper): Backupper class object
Returns:
int: QApplication Window exit code
"""
# Replace icon in taskbar
if os.name == "nt":
logging.info("Replacing icon in taskbar")
Expand All @@ -814,5 +827,6 @@ def start_gui(self, logging_handler: LoggingHandler.LoggingHandler, backupper: B
app = QApplication.instance() or QApplication(sys.argv)
app.setStyle("windows")
_ = _Window(self._config_manager, logging_handler, backupper)
app.exec_()
exit_code = app.exec_()
logging.info("GUI closed")
return exit_code
11 changes: 9 additions & 2 deletions LoggingHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ def worker_configurer(queue: multiprocessing.Queue, log_test_message: bool = Tru
queue (multiprocessing.Queue): logging queue
log_test_message (bool, optional): set to False to disable test log message with process PID. Defaults to True.
"""
# Setup queue handler
queue_handler = logging.handlers.QueueHandler(queue)
# Remove all current handlers
root_logger = logging.getLogger()
if root_logger.handlers:
for handler in root_logger.handlers:
root_logger.removeHandler(handler)

# Setup queue handler
queue_handler = logging.handlers.QueueHandler(queue)
root_logger.addHandler(queue_handler)
root_logger.setLevel(logging.INFO)

Expand All @@ -70,6 +72,11 @@ def _logging_listener(
# Get root logger
root_logger = logging.getLogger()

# Remove all current handlers (just in case)
if root_logger.handlers:
for handler in root_logger.handlers:
root_logger.removeHandler(handler)

# Setup logging into console
if console_logging:
import sys
Expand Down
11 changes: 7 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def main() -> None:

# Initialize logging, start logging for main process and start listeners
logging_handler = LoggingHandler.LoggingHandler()
LoggingHandler.worker_configurer(logging_handler.queue)
logging_handler.configure_and_start_listener(args.enable_console_logging)
LoggingHandler.worker_configurer(logging_handler.queue)

# Log software version and GitHub link
logging.info("FloppyCat Simple Backup Utility version: " + str(__version__))
Expand All @@ -98,15 +98,18 @@ def main() -> None:
# Initialize GUI
gui = GUIHandler.GUIHandler(config_manager)

# Load GUI (blocking)
gui.start_gui(logging_handler, backupper)
# Load GUI (blocking) and catch exit code
exit_code = gui.start_gui(logging_handler, backupper)

# If we're here, exit requested
logging.info("FloppyCat Simple Backup Utility exited successfully")
logging.info(f"FloppyCat Simple Backup Utility exited with code: {exit_code}")

# Finally, stop logging loop
logging_handler.queue.put(None)

# Return exit code
sys.exit(exit_code)


if __name__ == "__main__":
main()

0 comments on commit b1d34cc

Please sign in to comment.