From e5449e9e63dbe2c4aa4f48327f93e155b1b5b93c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Wed, 17 Feb 2021 17:45:11 +0100
Subject: [PATCH] added `terminating` property to `TerminableThread`

---
 CHANGELOG.md                         | 2 ++
 satella/__init__.py                  | 2 +-
 satella/coding/concurrent/thread.py  | 9 ++++++++-
 tests/test_coding/test_concurrent.py | 1 +
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index bcb2b0e4..4e6d2269 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1 +1,3 @@
 # v2.14.42
+
+* added `terminating` property to `TerminableThread`
diff --git a/satella/__init__.py b/satella/__init__.py
index 291cc51d..5a7b5935 100644
--- a/satella/__init__.py
+++ b/satella/__init__.py
@@ -1 +1 @@
-__version__ = '2.14.42a1'
+__version__ = '2.14.42a2'
diff --git a/satella/coding/concurrent/thread.py b/satella/coding/concurrent/thread.py
index 0158013d..94521e15 100644
--- a/satella/coding/concurrent/thread.py
+++ b/satella/coding/concurrent/thread.py
@@ -185,7 +185,7 @@ class TerminableThread(threading.Thread):
     >>> a = MeGrimlock().start()
     >>> a.terminate().join()
 
-    Flag whether to terminate is stored in **self.terminating**.
+    Property to check whether to terminate is stored in **self.terminating**.
 
     If you decide to override run(), you got to check periodically for **self._terminating**
     to become true. If it's true, then a termination request was received, and the thread should
@@ -306,6 +306,13 @@ class TerminableThread(threading.Thread):
         if self._terminating:
             raise SystemExit()
 
+    @property
+    def terminating(self) -> bool:
+        """
+        :return: Is this thread either alive and trying to terminate or dead and after termination?
+        """
+        return self._terminating
+
     def terminate(self, force: bool = False) -> 'TerminableThread':
         """
         Signal this thread to terminate.
diff --git a/tests/test_coding/test_concurrent.py b/tests/test_coding/test_concurrent.py
index c3bc04f8..a12f0906 100644
--- a/tests/test_coding/test_concurrent.py
+++ b/tests/test_coding/test_concurrent.py
@@ -451,6 +451,7 @@ class TestConcurrent(unittest.TestCase):
         self.assertTrue(t.is_alive())
         dct['a'] = True
         time.sleep(1)
+        self.assertTrue(t.terminating)
         self.assertFalse(t.is_alive())
 
     def test_cg_proforma(self):
-- 
GitLab