當前位置: 首頁>>代碼示例>>Python>>正文


Python Pool.all方法代碼示例

本文整理匯總了Python中pool.Pool.all方法的典型用法代碼示例。如果您正苦於以下問題:Python Pool.all方法的具體用法?Python Pool.all怎麽用?Python Pool.all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pool.Pool的用法示例。


在下文中一共展示了Pool.all方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Server

# 需要導入模塊: from pool import Pool [as 別名]
# 或者: from pool.Pool import all [as 別名]

#.........這裏部分代碼省略.........
        """
        asyncio.async(self.send(peer, request))

    @asyncio.coroutine
    def wait(self):
        """
        Wait for the next interval.
        """
        tic = self._heartbeat_interval / 1000 - self._loop.time() + self._last_interval
        yield from asyncio.sleep(tic)

        self.reset_interval()

    def to_leader(self):
        self.append_entries()
        self.state = State.LEADER
        self.voted = None
        self.votes = set()

        for peer in self._pool:
            peer.match = -1
            peer.next = self._log.index + 1

    def to_follower(self, term):
        self.state = State.FOLLOWER
        self.term = term
        self.voted = None
        self.votes = set()

    def append_entries(self, peer=None):
        """
        Append entries RPC.
        """
        peers = self._pool.all() if peer is None else [peer]

        for peer in peers:
            log_entries = self._log[peer.next:]
            log_index, log_term, _ = self._log[peer.next - 1]

            request = {'rpc': 'append_entries_req',
                       'peer_id': self.peer_id,
                       'term': self.term,
                       'log_commit': self._log.commit,
                       'log_entries': log_entries,
                       'log_index': log_index,
                       'log_term': log_term,
                       }

            self.send_async(peer, request)

        self._logger.debug('broadcasting append entries')

    def request_vote(self):
        """
        Request vote RPC.
        """
        self.reset_heartbeat()
        self.reset_timeout()

        self.state = State.CANDIDATE
        self.term += 1
        self.voted = self.peer_id
        self.votes = set([self.peer_id])

        request = {'rpc': 'request_vote_req',
                   'peer_id': self.peer_id,
開發者ID:guilload,項目名稱:aio-raft,代碼行數:70,代碼來源:server.py


注:本文中的pool.Pool.all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。