diff --git a/fluent/asynchandler.py b/fluent/asynchandler.py index 397608e..c2744bf 100644 --- a/fluent/asynchandler.py +++ b/fluent/asynchandler.py @@ -1,4 +1,4 @@ -from fluent import asyncsender, handler +from fluent import asyncsender, handler, sender class FluentHandler(handler.FluentHandler): @@ -6,6 +6,12 @@ class FluentHandler(handler.FluentHandler): Asynchronous Logging Handler for fluent. """ + def getSenderInstance(self, **kwargs): + try: + return super().getSenderInstance(**kwargs) + except RuntimeError: + return sender.FluentSender(**kwargs) + def getSenderClass(self): return asyncsender.FluentSender diff --git a/tests/test_asynchandler.py b/tests/test_asynchandler.py index 7bbf108..3160017 100644 --- a/tests/test_asynchandler.py +++ b/tests/test_asynchandler.py @@ -259,6 +259,14 @@ def test_exception_message(self): self.assertTrue('tests/test_asynchandler.py", line' in message) self.assertTrue("Exception: sample exception" in message) + @mock.patch('threading.Thread') + def test_close_during_interpreter_shutdown(self, thread_mock): + thread_mock.return_value.start.side_effect = RuntimeError("can't create new thread at interpreter shutdown") + + handler = self.get_handler_class()("app.follow", port=self._port) + handler.close() + thread_mock.return_value.start.assert_called_once() + class TestHandlerWithCircularQueue(unittest.TestCase): Q_SIZE = 3