[elbe-devel] [PATCH 1/2] elbepack: log: handle os.devnull
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Thu Aug 22 14:24:06 CEST 2024
os.devnull is not an actual stream but just a string to be used with
open(). Opening /dev/null and then leaving that file around is
problematic, as it is essentially a leaked file handle.
Implement a simple class to represent /dev/null.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/log.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/elbepack/log.py b/elbepack/log.py
index 88e331f2eb1f..6613e500b042 100644
--- a/elbepack/log.py
+++ b/elbepack/log.py
@@ -98,9 +98,17 @@ class ThreadFilter(logging.Filter):
return retval
+class _NullStream:
+ def write(self, data):
+ pass
+
+
def add_stream_handlers(streams):
for stream in streams:
+ if stream == os.devnull:
+ stream = _NullStream()
+
out = logging.StreamHandler(stream)
out.addFilter(ThreadFilter([root, log, report, validation, soap])),
out.setFormatter(context_fmt)
--
2.46.0
More information about the elbe-devel
mailing list