Merge "Just use a deque vs reverse pushing/popping"
This commit is contained in:
commit
7bbce9e23c
|
@ -81,14 +81,6 @@ def get_callback_name(cb):
|
||||||
return ".".join(segments)
|
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):
|
def get_optimal_thread_count(default=2):
|
||||||
"""Try to guess optimal thread count for current system."""
|
"""Try to guess optimal thread count for current system."""
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import collections
|
||||||
import fractions
|
import fractions
|
||||||
import functools
|
import functools
|
||||||
import heapq
|
import heapq
|
||||||
|
@ -257,12 +258,8 @@ def _run_callback_no_retain(now_func, cb, *args, **kwargs):
|
||||||
def _build(now_func, callables, next_run_scheduler):
|
def _build(now_func, callables, next_run_scheduler):
|
||||||
schedule = _Schedule()
|
schedule = _Schedule()
|
||||||
now = None
|
now = None
|
||||||
immediates = []
|
immediates = collections.deque()
|
||||||
# Reverse order is used since these are later popped off (and to
|
for index, (cb, _cb_name, args, kwargs) in enumerate(callables):
|
||||||
# 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:
|
|
||||||
if cb._periodic_run_immediately:
|
if cb._periodic_run_immediately:
|
||||||
immediates.append(index)
|
immediates.append(index)
|
||||||
else:
|
else:
|
||||||
|
@ -556,7 +553,7 @@ class PeriodicWorker(object):
|
||||||
if self._immediates:
|
if self._immediates:
|
||||||
# Run & schedule its next execution.
|
# Run & schedule its next execution.
|
||||||
try:
|
try:
|
||||||
index = self._immediates.pop()
|
index = self._immediates.popleft()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue