From bb4304810b0cc335e918a52160654c991d1c53d9 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 2 Feb 2015 22:34:34 -0800 Subject: [PATCH] Just directly access the callback attributes Since we perform validation on the callbacks in the constructor we don't need to continue being cautious after that point so we can remove the usage of getattr and just access the underlying callback properties that must have already existed. Change-Id: I0c86506488d139268cb30f6c346484b2e978697f --- taskflow/types/periodic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/taskflow/types/periodic.py b/taskflow/types/periodic.py index bbb494d3..2717be03 100644 --- a/taskflow/types/periodic.py +++ b/taskflow/types/periodic.py @@ -111,11 +111,11 @@ class PeriodicWorker(object): self._immediates = [] now = _now() for i, (cb, cb_name) in enumerate(self._callables): - spacing = getattr(cb, '_periodic_spacing') + spacing = cb._periodic_spacing next_run = now + spacing heapq.heappush(self._schedule, (next_run, i)) for (cb, cb_name) in reversed(self._callables): - if getattr(cb, '_periodic_run_immediately', False): + if cb._periodic_run_immediately: self._immediates.append((cb, cb_name)) def __len__(self): @@ -154,7 +154,7 @@ class PeriodicWorker(object): when_next = next_run - now if when_next <= 0: cb, cb_name = self._callables[i] - spacing = getattr(cb, '_periodic_spacing') + spacing = cb._periodic_spacing LOG.debug("Calling periodic callable '%s' (it runs every" " %s seconds)", cb_name, spacing) self._safe_call(cb, cb_name) @@ -175,5 +175,5 @@ class PeriodicWorker(object): self._tombstone.clear() self._immediates = [] for (cb, cb_name) in reversed(self._callables): - if getattr(cb, '_periodic_run_immediately', False): + if cb._periodic_run_immediately: self._immediates.append((cb, cb_name))