Francesco Romani has uploaded a new change for review. Change subject: sampling: hoststats: don't inherit from thread ......................................................................
sampling: hoststats: don't inherit from thread Inheriting from Thread is bad practice. This patch makes sampling.HostStatsThread use a thread attribute, favoring composition over inheritance. No intended functional changes. Change-Id: I0ddb419e8d64612e8b035c359f5679c376113f9a Signed-off-by: Francesco Romani <[email protected]> --- M tests/samplingTests.py M vdsm/virt/sampling.py 2 files changed, 14 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/43/47943/1 diff --git a/tests/samplingTests.py b/tests/samplingTests.py index e3921ea..621b236 100644 --- a/tests/samplingTests.py +++ b/tests/samplingTests.py @@ -213,7 +213,7 @@ # we cannot monkey patch, it will interfer on threading internals self._hs._stopEvent = FakeEvent() self._hs.start() - self._hs.join() + self._hs.wait() first, last, _ = samples.stats() self.assertEqual(first.id, FakeHostSample.counter - diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py index bf249da..71e8381 100644 --- a/vdsm/virt/sampling.py +++ b/vdsm/virt/sampling.py @@ -541,17 +541,14 @@ host_samples = SampleWindow(size=HOST_STATS_AVERAGING_WINDOW) -class HostStatsThread(threading.Thread): +class HostStatsThread(object): """ A thread that periodically samples host statistics. """ _CONNLOG = logging.getLogger('connectivity') def __init__(self, log, samples=host_samples, clock=utils.monotonic_time): - threading.Thread.__init__(self) - self.daemon = True self._log = log - self._stopEvent = threading.Event() self._samples = samples self._pid = os.getpid() @@ -561,10 +558,21 @@ hoststats.start(clock) + self._stopEvent = threading.Event() + + self._thread = threading.Thread(target=self._run, name='hoststats') + self._thread.daemon = True + + def start(self): + self._thread.start() + def stop(self): self._stopEvent.set() - def run(self): + def wait(self): + self._thread.join() + + def _run(self): try: # wait a bit before starting to sample time.sleep(self._sampleInterval) -- To view, visit https://gerrit.ovirt.org/47943 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0ddb419e8d64612e8b035c359f5679c376113f9a Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
