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

`IntervalTerminableThread` will now terminate faster

parent 39938ed3
No related branches found
No related tags found
No related merge requests found
......@@ -3,3 +3,4 @@
* added `MetricDataCollection.remove_internals`
* added `whereis`
* added `timeout` to `ThreadCollection.join`
* `IntervalTerminableThread` will now terminate faster
__version__ = '2.16.7a2'
__version__ = '2.16.7a3'
......@@ -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:
......
......@@ -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)
......
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