Compare commits

...

6 Commits

Author SHA1 Message Date
Clemens Schwaighofer
6090995eba v0.22.3: Fixes in Log for atexit calls for queue close 2025-08-05 13:24:16 +09:00
Clemens Schwaighofer
60db747d6d More fixes for the queue clean up
Changed that we call stop_listener and not _cleanup on exit
Then call _cleanup from the stop listener
We only need that if we have listeners (queue) anyway
2025-08-05 13:22:54 +09:00
Clemens Schwaighofer
a7a4141f58 v0.22.2: Log remove __del__ call for clean up, this broke everything 2025-08-05 10:37:57 +09:00
Clemens Schwaighofer
2b04cbe239 Remove Log __del__ cleanup 2025-08-05 10:36:49 +09:00
Clemens Schwaighofer
765cc061c1 v0.22.1: Log update with closing queue on exit or abort 2025-08-05 10:33:55 +09:00
Clemens Schwaighofer
80319385f0 Add Log exist queue clean up if queue is set
to avoid hung threads on errors
2025-08-05 10:32:33 +09:00
3 changed files with 15 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
# MARK: Project info # MARK: Project info
[project] [project]
name = "corelibs" name = "corelibs"
version = "0.22.0" version = "0.22.3"
description = "Collection of utils for Python scripts" description = "Collection of utils for Python scripts"
readme = "README.md" readme = "README.md"
requires-python = ">=3.13" requires-python = ">=3.13"

View File

@@ -10,6 +10,7 @@ import logging
from datetime import datetime from datetime import datetime
import time import time
from pathlib import Path from pathlib import Path
import atexit
from typing import MutableMapping, TextIO, TypedDict, Any, TYPE_CHECKING, cast from typing import MutableMapping, TextIO, TypedDict, Any, TYPE_CHECKING, cast
from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel from corelibs.logging_handling.logging_level_handling.logging_level import LoggingLevel
from corelibs.string_handling.text_colors import Colors from corelibs.string_handling.text_colors import Colors
@@ -282,6 +283,15 @@ class LogParent:
return False return False
return True return True
def _cleanup(self):
"""cleanup for any open queues in case we have an abort"""
if not self.log_queue:
return
self.flush()
# Close the queue properly
self.log_queue.close()
self.log_queue.join_thread()
# MARK: log level handling # MARK: log level handling
def set_log_level(self, handler_name: str, log_level: LoggingLevel) -> bool: def set_log_level(self, handler_name: str, log_level: LoggingLevel) -> bool:
""" """
@@ -634,6 +644,7 @@ class Log(LogParent):
if log_queue is None: if log_queue is None:
return return
self.log_queue = log_queue self.log_queue = log_queue
atexit.register(self.stop_listener)
self.listener = logging.handlers.QueueListener( self.listener = logging.handlers.QueueListener(
self.log_queue, self.log_queue,
*self.handlers.values(), *self.handlers.values(),
@@ -648,6 +659,7 @@ class Log(LogParent):
if self.listener is not None: if self.listener is not None:
self.flush() self.flush()
self.listener.stop() self.listener.stop()
self._cleanup()
# MARK: init main log # MARK: init main log
def __init_log(self, log_name: str) -> None: def __init_log(self, log_name: str) -> None:

4
uv.lock generated
View File

@@ -1,5 +1,5 @@
version = 1 version = 1
revision = 2 revision = 3
requires-python = ">=3.13" requires-python = ">=3.13"
[[package]] [[package]]
@@ -44,7 +44,7 @@ wheels = [
[[package]] [[package]]
name = "corelibs" name = "corelibs"
version = "0.21.0" version = "0.22.2"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "jmespath" }, { name = "jmespath" },