本文整理汇总了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,