Merge "Just use a deque vs reverse pushing/popping"

This commit is contained in:
Jenkins 2015-09-16 11:57:02 +00:00 committed by Gerrit Code Review
commit 7bbce9e23c
2 changed files with 4 additions and 15 deletions

View File

@ -81,14 +81,6 @@ def get_callback_name(cb):
return ".".join(segments)
def reverse_enumerate(items):
"""Yields (index, item) from given list/tuple in reverse order."""
idx = len(items)
while idx > 0:
yield (idx - 1, items[idx - 1])
idx -= 1
def get_optimal_thread_count(default=2):
"""Try to guess optimal thread count for current system."""
try:

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import fractions
import functools
import heapq
@ -257,12 +258,8 @@ def _run_callback_no_retain(now_func, cb, *args, **kwargs):
def _build(now_func, callables, next_run_scheduler):
schedule = _Schedule()
now = None
immediates = []
# Reverse order is used since these are later popped off (and to
# ensure the popping order is first -> last we need to append them
# in the opposite ordering last -> first).
reverse_it = utils.reverse_enumerate(callables)
for index, (cb, _cb_name, args, kwargs) in reverse_it:
immediates = collections.deque()
for index, (cb, _cb_name, args, kwargs) in enumerate(callables):
if cb._periodic_run_immediately:
immediates.append(index)
else:
@ -556,7 +553,7 @@ class PeriodicWorker(object):
if self._immediates:
# Run & schedule its next execution.
try:
index = self._immediates.pop()
index = self._immediates.popleft()
except IndexError:
pass
else: