diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f5ec7f8dce377b8cc472b36a1e6871c674a0654..418deac28dd7d934a910e48947577c2b40aaf74a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,4 @@ * added `MetricDataCollection.remove_internals` * added `whereis` * added `timeout` to `ThreadCollection.join` +* `IntervalTerminableThread` will now terminate faster diff --git a/satella/__init__.py b/satella/__init__.py index 3d11c528e46ce4b5449dfb84b91e6c21893c1114..635f2cd2853edd44331ef67adb77a986a84f41c4 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.16.7a2' +__version__ = '2.16.7a3' diff --git a/satella/coding/concurrent/thread.py b/satella/coding/concurrent/thread.py index 4ad78f12a00e47ccbef9926099411d6b8f0c4da5..5958d804d3dc72bcde446c63f4cc42e02b2860e0 100644 --- a/satella/coding/concurrent/thread.py +++ b/satella/coding/concurrent/thread.py @@ -435,6 +435,8 @@ class IntervalTerminableThread(TerminableThread, metaclass=ABCMeta): Called each cycle. + You are meant to override this, as by default this does nothing. + :param time_taken: how long did calling .loop() take """ @@ -443,6 +445,8 @@ class IntervalTerminableThread(TerminableThread, metaclass=ABCMeta): while not self._terminating: with measure() as measurement: self.loop() + if self._terminating: + break time_taken = measurement() time_to_sleep = self.seconds - time_taken if time_to_sleep < 0: diff --git a/tests/test_coding/test_concurrent.py b/tests/test_coding/test_concurrent.py index 8bde1c18c8117899775f8fb7dd5a2cf001a23de1..13aa60d07fa6d2fdb77e3da672dd5b12b456d3d5 100644 --- a/tests/test_coding/test_concurrent.py +++ b/tests/test_coding/test_concurrent.py @@ -547,10 +547,9 @@ class TestConcurrent(unittest.TestCase): mtt.start() a = mtt.a time.sleep(0.3) - self.assertEqual(mtt.a, a) + self.assertIn(mtt.a, (1, 2)) self.assertFalse(mtt.overrun) time.sleep(1.2) - self.assertEqual(mtt.a, a+1) self.assertFalse(mtt.overrun) time.sleep(4) self.assertTrue(mtt.overrun)