Apply max_staleness, in seconds, to a Selection with a known primary.
505493
def _with_primary(max_staleness, selection):
    """"""
    primary = selection.primary
    sds = []

    for s in selection.server_descriptions:
        if s.server_type == SERVER_TYPE.RSSecondary:
            # See max-staleness.rst for explanation of this formula.
            staleness = (
                (s.last_update_time - s.last_write_date) -
                (primary.last_update_time - primary.last_write_date) +
                selection.heartbeat_frequency)

            if staleness <= max_staleness:
                sds.append(s)
        else:
            sds.append(s)

    return selection.with_server_descriptions(sds)
783816
def update(self):
        """"""
        expire_time = time.time() - self.max_time
        while self.row_deque and self.time_deque[0] < expire_time:
            self.row_deque.popleft()  # FIFO
            self.time_deque.popleft()
1069897
def _siftdown_max(heap, startpos, pos):
    ''
    newitem = heap[pos]
    # Follow the path to the root, moving parents down until finding a place
    # newitem fits.
    while pos > startpos:
        parentpos = (pos - 1) >> 1
        parent = heap[parentpos]
        if parent < newitem:
            heap[pos] = parent
            pos = parentpos
            continue
        break
    heap[pos] = newitem
232144
private void primAdd(IEntityLock lock, Date expiration) throws LockingException {
        long now = System.currentTimeMillis();
        long willExpire = expiration.getTime();
        long cacheIntervalSecs = (willExpire - now) / 1000;

        if (cacheIntervalSecs > 0) {
            SmartCache sc = (SmartCache) getLockCache(lock.getEntityType());

            synchronized (sc) {
                sc.put(getCacheKey(lock), lock, (cacheIntervalSecs));
            }
        }
        // Else the lock has already expired.
    }
1308022
def ensure_hbounds(self):
        """"""
        self.cursor.x = min(max(0, self.cursor.x), self.columns - 1)
273700
def _cache_key_select_user(method, self, allow_blank=True, style=None):
    
    key = update_timer(), allow_blank, style
    return key
1005158
def selection(self, index):
        """"""
        self.update()
        self.isActiveWindow()
        self._parent.delete_btn.setEnabled(True)
1212753
def optimized(code, silent=True, ignore_errors=True):
    """"""
    return constant_fold(code, silent=silent, ignore_errors=ignore_errors)
559928
def decaying(start, stop, decay):
    """"""

    curr = float(start)
    while True:
        yield max(curr, stop)
        curr -= (decay)
1302831
public void waitForUpdate() {

        CmsWaitHandle handle = new CmsWaitHandle(true);
        addWaitHandle(handle);
        handle.enter(Long.MAX_VALUE);
    }
357023
private void updateMax(int idx, long v) {
    AtomicLong current = max.getCurrent(idx);
    long m = current.get();
    while (v > m) {
      if (current.compareAndSet(m, v)) {
        break;
      }
      m = current.get();
    }
  }
615879
public void sessionMaxInactiveTimeSet(ISession session, int old, int newval) {
        _sessionStateEventDispatcher.sessionMaxInactiveTimeSet(session, old, newval);

    }
161272
def execute(self, string, max_tacts=None):
        """"""
        counter = 0
        self.last_rule = None

        while True:
            string = self.execute_once(string)
            if self.last_rule is None or self.last_rule[2]:
                break
            counter += 1
            if max_tacts is not None and counter >= max_tacts:
                raise TimeoutError("algorithm hasn't been stopped")

        return string
388678
private synchronized void removeExpiredEntriesSynced(long pTime) {
        if (pTime > nextExpiryTime) {
            ////
            long next = Long.MAX_VALUE;
            nextExpiryTime = next; // Avoid multiple runs...
            for (Iterator<Entry<K, V>> iterator = new EntryIterator(); iterator.hasNext();) {
                TimedEntry<K, V> entry = (TimedEntry<K, V>) iterator.next();
                ////
                long expires = entry.expires();
                if (expires < next) {
                    next = expires;
                }
                ////
            }
            ////
            nextExpiryTime = next;
        }
    }
706452
def _cache_key_select_sample_type(method, self, allow_blank=True, multiselect=False, style=None):
    
    key = update_timer(), allow_blank, multiselect, style
    return key
1323482
def lastKey(self, key):
        """"""
        update = self._updateList(key)[0]
        return (update[0].key
                if update
                else None)
236723
def _heapreplace_max(heap, item):
    """"""
    returnitem = heap[0]    # raises appropriate IndexError if heap is empty
    heap[0] = item
    _siftup_max(heap, 0)
    return returnitem