From 9412ca030b0495ccc37ce5817efaf25f60ae797c Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Fri, 11 Sep 2020 15:57:27 +0100 Subject: [PATCH] Provide (no-op) close method. Some contexts try to close their reference to the stderr stream at logging shutdown, this ensures these don't break. --- airflow/utils/log/logging_mixin.py | 8 ++++++++ tests/utils/test_logging_mixin.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/airflow/utils/log/logging_mixin.py b/airflow/utils/log/logging_mixin.py index 90131d10402da..95d137d3bc588 100644 --- a/airflow/utils/log/logging_mixin.py +++ b/airflow/utils/log/logging_mixin.py @@ -95,6 +95,14 @@ def __init__(self, logger, level): self.level = level self._buffer = str() + def close(self): + """ + Provide close method, for compatibility with the io.IOBase interface. + + This is a no-op method. + """ + pass + @property def closed(self): """ diff --git a/tests/utils/test_logging_mixin.py b/tests/utils/test_logging_mixin.py index 4f557167b6fdb..98a04c252baec 100644 --- a/tests/utils/test_logging_mixin.py +++ b/tests/utils/test_logging_mixin.py @@ -116,3 +116,10 @@ def test_encoding(self): log = StreamLogWriter(logger, 1) self.assertIsNone(log.encoding) + + def test_iobase_compatibility(self): + log = StreamLogWriter(None, 1) + + self.assertFalse(log.closed) + # has no specific effect + log.close()