Get the current semaphore state by fetching all
 conterder keys and the lock key
427717
def semaphore_state
      options = { decode_values: true, recurse: true }
      @state = Diplomat::Kv.get(prefix, options, :return)
      decode_semaphore_state unless state.empty?
      state
    end
528448
def get(self):
        """"""
        with self._mutex:
            entry = self._queue.pop()
            del self._block_map[entry[2]]
            return entry[2]
218772
def _all_keys(self):
        """"""
        file_keys = [self._filename_to_key(fn) for fn in self._all_filenames()]
        if self._sync:
            return set(file_keys)
        else:
            return set(file_keys + list(self._buffer))
356747
def get_state(self):
        """"""
        return {"started": (True if self.background_process and
                            self.background_process.is_alive() else False),
                "paused": self._pause.value,
                "stopped": self._end.value,
                "tasks": len(self.current_tasks),
                "busy_tasks": len(self.busy_tasks),
                "free_tasks": len(self.free_tasks)}
1347657
def get_action(self, key):
        
        index_local_timestamp = self.get_index_local_timestamp(key)
        real_local_timestamp = self.get_real_local_timestamp(key)
        remote_timestamp = self.get_remote_timestamp(key)
        return get_sync_state(
            index_local_timestamp, real_local_timestamp, remote_timestamp
        )
382470
def get_lock_behaviour(triggers, all_data, lock):
    """"""
    updates = {}
    lock_key = config._forward_aliases.get(Constants.VERSION_LOCK_FIELD)
    # if we are explicitly setting or locking the version, then set the lock field True anyway
    if lock:
        updates[Constants.VERSION_LOCK_FIELD] = config.VERSION_LOCK_VALUE
    elif (
        triggers
        and lock_key
        and str(all_data.get(lock_key)) == str(config.VERSION_LOCK_VALUE)
    ):
        triggers.clear()
        updates[Constants.VERSION_LOCK_FIELD] = config.VERSION_UNLOCK_VALUE
    return updates
923678
def _get_keycachelike(self, keycache, keys, get_adds_dels, parentity, branch, turn, tick, *, forward):
        
        keycache_key = parentity + (branch,)
        keycache2 = keycache3 = None
        if keycache_key in keycache:
            keycache2 = keycache[keycache_key]
            if turn in keycache2:
                keycache3 = keycache2[turn]
                if tick in keycache3:
                    return keycache3[tick]
        if forward:
            # Take valid values from the past of a keycache and copy them forward, into the present.
            # Assumes that time is only moving forward, never backward, never skipping any turns or ticks,
            # and any changes to the world state are happening through allegedb proper, meaning they'll all get cached.
            # In LiSE this means every change to the world state should happen inside of a call to
            # ``Engine.next_turn`` in a rule.
            if keycache2 and keycache2.rev_gettable(turn):
                # there's a keycache from a prior turn in this branch. Get it
                if turn not in keycache2:
                    # since it's not this *exact* turn there might be changes...
                    old_turn = keycache2.rev_before(turn)
                    old_turn_kc = keycache2[turn]
                    added, deleted = get_adds_dels(
                        keys[parentity], branch, turn, tick, stoptime=(
                            branch, old_turn, old_turn_kc.end
                        )
                    )
                    ret = old_turn_kc[old_turn_kc.end].union(added).difference(deleted)
                    # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                    new_turn_kc = WindowDict()
                    new_turn_kc[tick] = ret
                    keycache2[turn] = new_turn_kc
                    return ret
                if not keycache3:
                    keycache3 = keycache2[turn]
                if tick not in keycache3:
                    if keycache3.rev_gettable(tick):
                        added, deleted = get_adds_dels(
                            keys[parentity], branch, turn, tick, stoptime=(
                                branch, turn, keycache3.rev_before(tick)
                            )
                        )
                        ret = keycache3[tick].union(added).difference(deleted)
                        # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                        keycache3[tick] = ret
                        return ret
                    else:
                        turn_before = keycache2.rev_before(turn)
                        tick_before = keycache2[turn_before].end
                        keys_before = keycache2[turn_before][tick_before]
                        added, deleted = get_adds_dels(
                            keys[parentity], branch, turn, tick, stoptime=(
                                branch, turn_before, tick_before
                            )
                        )
                        ret = keycache3[tick] = keys_before.union(added).difference(deleted)
                        # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                        return ret
                # assert kcturn[tick] == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                return keycache3[tick]
            else:
                for (parbranch, parturn, partick) in self.db._iter_parent_btt(branch, turn, tick):
                    par_kc_key = parentity + (parbranch,)
                    if par_kc_key in keycache:
                        kcpkc = keycache[par_kc_key]
                        if parturn in kcpkc and kcpkc[parturn].rev_gettable(partick):
                            parkeys = kcpkc[parturn][partick]
                            break
                        elif kcpkc.rev_gettable(parturn-1):
                            partkeys = kcpkc[parturn-1]
                            parkeys = partkeys[partkeys.end]
                            break
                else:
                    parkeys = frozenset()
                keycache2 = SettingsTurnDict()
                added, deleted = get_adds_dels(
                    keys[parentity], branch, turn, tick, stoptime=(
                        parbranch, parturn, partick
                    )
                )
                ret = parkeys.union(added).difference(deleted)
                keycache2[turn] = {tick: ret}
                keycache[keycache_key] = keycache2
                # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                return ret
        ret = frozenset(get_adds_dels(keys[parentity], branch, turn, tick)[0])
        if keycache2:
            if keycache3:
                keycache3[tick] = ret
            else:
                keycache2[turn] = {tick: ret}
        else:
            kcc = SettingsTurnDict()
            kcc[turn] = {tick: ret}
            keycache[keycache_key] = kcc
        return ret
445657
def _get_keycache(self, parentity, branch, turn, tick, *, forward):
        
        lru_append(self.keycache, self._kc_lru, (parentity+(branch,), turn, tick), KEYCACHE_MAXSIZE)
        return self._get_keycachelike(
            self.keycache, self.keys, self._get_adds_dels,
            parentity, branch, turn, tick, forward=forward
        )
1229263
def current_state(self):
        """"""
        state = {}
        for s in self._state:
            state[s] = getattr(self, s)
        return state
105089
private function getDefaultLock()
    {
        if ($this->isSysvIPCLoaded()) {
            return new SemaphoreLock(
                $this->getSysvKey(crc32($this->cacheKey))
            );
        }

        return new FlockLock($this->cacheKey);
    }
953499
int waitingThreadsCount() {
		int result = 0;
		for (final CountingLock lock : key2lock.values()) {
			result += lock.getQueueLength();
		}
		return result;
	}
1005419
def wait(self, key, index=0, recursive=False, sorted=False, quorum=False,
             timeout=None):
        """"""
        return self.adapter.get(key, recursive=recursive, sorted=sorted,
                                quorum=quorum, wait=True, wait_index=index,
                                timeout=timeout)
1369177
def when_available(self, key: Hashable, **when_kwargs) -> StateWatcher:
        
        return self.when(lambda snapshot: key in snapshot, **when_kwargs)
1042679
def read_hotkey(suppress=True):
    
    queue = _queue.Queue()
    fn = lambda e: queue.put(e) or e.event_type == KEY_DOWN
    hooked = hook(fn, suppress=suppress)
    while True:
        event = queue.get()
        if event.event_type == KEY_UP:
            unhook(hooked)
            with _pressed_events_lock:
                names = [e.name for e in _pressed_events.values()] + [event.name]
            return get_hotkey_name(names)
637665
@SuppressWarnings("PMD.AvoidCatchingNPE")
  private Map<K, V> getAll(Set<? extends K> keys, boolean updateAccessTime) {
    requireNotClosed();
    boolean statsEnabled = statistics.isEnabled();
    long start = statsEnabled ? ticker.read() : 0L;
    try {
      Map<K, Expirable<V>> entries = getAndFilterExpiredEntries(keys, updateAccessTime);

      if (entries.size() != keys.size()) {
        List<K> keysToLoad = keys.stream()
            .filter(key -> !entries.containsKey(key))
            .collect(Collectors.<K>toList());
        entries.putAll(cache.getAll(keysToLoad));
      }

      Map<K, V> result = copyMap(entries);
      if (statsEnabled) {
        statistics.recordGetTime(ticker.read() - start);
      }
      return result;
    } catch (NullPointerException | IllegalStateException | ClassCastException | CacheException e) {
      throw e;
    } catch (RuntimeException e) {
      throw new CacheException(e);
    } finally {
      dispatcher.awaitSynchronous();
    }
  }
113976
def get_all_keys(self, start=None):
        
        s = self.stream
        if not start:
            start = HEADER_SIZE + self.block_size * self.root_block
        s.seek(start)
        block_type = s.read(2)
        if block_type == LEAF:
            reader = LeafReader(self)
            num_keys = struct.unpack('>i', reader.read(4))[0]
            for _ in range(num_keys):
                cur_key = reader.read(self.key_size)
                # We to a tell/seek here so that the user can read from
                # the file while this loop is still being run
                cur_pos = s.tell()
                yield cur_key
                s.seek(cur_pos)
                length = sbon.read_varint(reader)
                reader.seek(length, 1)
        elif block_type == INDEX:
            (_, num_keys, first_child) = struct.unpack('>Bii', s.read(9))
            children = [first_child]
            for _ in range(num_keys):
                # Skip the key field.
                _ = s.read(self.key_size)
                # Read pointer to the child block.
                next_child = struct.unpack('>i', s.read(4))[0]
                children.append(next_child)
            for child_loc in children:
                for key in self.get_all_keys(HEADER_SIZE + self.block_size * child_loc):
                    yield key
        elif block_type == FREE:
            pass
        else:
            raise Exception('Unhandled block type: {}'.format(block_type))
772780
private BlockingQueue<V> retrieveSharedQueue(String key) {
		BlockingQueue<V> queue = mediations.get(key);
		if (queue == null) {
			queue = new ArrayBlockingQueue<V>(1);
			BlockingQueue<V> commonQueue = mediations.putIfAbsent(key, queue);
			return commonQueue != null ? commonQueue : queue;
		} else {
			return queue;
		}
	}