From e978eca3635f4a92139e3c7c47a6b28586062cc0 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 12 Sep 2014 18:49:29 -0700 Subject: [PATCH] Allow stopwatches to be restarted It is quite useful to allow a stopwatch to be reset or restarted in a single operation, instead of having to handle this logic outside of the stopwatch object, which is error-prone and unnecessary to require users to reinvent. Part of blueprint process-executor Change-Id: Ie0304a4f1d5f6bf0460e9a134762d1403da56375 --- taskflow/types/timing.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/taskflow/types/timing.py b/taskflow/types/timing.py index decada4a..ab9a4c48 100644 --- a/taskflow/types/timing.py +++ b/taskflow/types/timing.py @@ -73,6 +73,12 @@ class StopWatch(object): self._state = self._STARTED return self + def restart(self): + if self._state == self._STARTED: + self.stop() + self.start() + return self + def elapsed(self): if self._state == self._STOPPED: return max(0.0, float(timeutils.delta_seconds(self._started_at,