Skip to content
Snippets Groups Projects
Commit e5449e9e authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

added `terminating` property to `TerminableThread`

parent 18e1454b
No related branches found
No related tags found
No related merge requests found
# v2.14.42 # v2.14.42
* added `terminating` property to `TerminableThread`
__version__ = '2.14.42a1' __version__ = '2.14.42a2'
...@@ -185,7 +185,7 @@ class TerminableThread(threading.Thread): ...@@ -185,7 +185,7 @@ class TerminableThread(threading.Thread):
>>> a = MeGrimlock().start() >>> a = MeGrimlock().start()
>>> a.terminate().join() >>> 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** 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 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): ...@@ -306,6 +306,13 @@ class TerminableThread(threading.Thread):
if self._terminating: if self._terminating:
raise SystemExit() 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': def terminate(self, force: bool = False) -> 'TerminableThread':
""" """
Signal this thread to terminate. Signal this thread to terminate.
......
...@@ -451,6 +451,7 @@ class TestConcurrent(unittest.TestCase): ...@@ -451,6 +451,7 @@ class TestConcurrent(unittest.TestCase):
self.assertTrue(t.is_alive()) self.assertTrue(t.is_alive())
dct['a'] = True dct['a'] = True
time.sleep(1) time.sleep(1)
self.assertTrue(t.terminating)
self.assertFalse(t.is_alive()) self.assertFalse(t.is_alive())
def test_cg_proforma(self): def test_cg_proforma(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment