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
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user