本文整理汇总了Python中Client.Client.waitForCommands方法的典型用法代码示例。如果您正苦于以下问题:Python Client.waitForCommands方法的具体用法?Python Client.waitForCommands怎么用?Python Client.waitForCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Client.Client
的用法示例。
在下文中一共展示了Client.waitForCommands方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import waitForCommands [as 别名]
def main():
# Establish the server cluster
s1 = Server()
s2 = Server()
s3 = Server()
s4 = Server()
s5 = Server()
s1.setNeighbors([s2, s3, s4, s5])
s2.setNeighbors([s1, s3, s4, s5])
s3.setNeighbors([s2, s1, s4, s5])
s4.setNeighbors([s2, s3, s1, s5])
s5.setNeighbors([s2, s3, s4, s1])
t1 = Thread(target=s1.electionTimeout)
t1.start()
time.sleep(5)
t2 = Thread(target=s2.electionTimeout)
t2.start()
t3 = Thread(target=s3.electionTimeout)
t3.start()
t4 = Thread(target=s4.electionTimeout)
t4.start()
t5 = Thread(target=s5.electionTimeout)
t5.start()
# Connect the client to the cluster leader
c1 = Client()
c1.connectClientToLeader(s2.neighbors)
# Use the command line
c1.waitForCommands()
示例2: testClientLoop
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import waitForCommands [as 别名]
def testClientLoop():
# Establish cluster
s1 = Server()
s2 = Server()
s3 = Server()
# Set cluster membership
s1.setNeighbors([s2, s3])
s2.setNeighbors([s1, s3])
s3.setNeighbors([s1, s2])
# Create cluster leader
# Request an election
s3.requestVotes()
# Connect the client to the cluster leader through a non-leader
c1 = Client()
c1.connectClientToLeader(s3.neighbors)
# Use the command line
c1.waitForCommands()
示例3: testClientLoopWithTimeout
# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import waitForCommands [as 别名]
def testClientLoopWithTimeout():
s1 = Server()
s2 = Server()
s3 = Server()
s1.setNeighbors([s2, s3])
s2.setNeighbors([s1, s3])
s3.setNeighbors([s1, s2])
t1 = Thread(target=s1.electionTimeout)
t1.start()
time.sleep(5)
t2 = Thread(target=s2.electionTimeout)
t2.start()
t3 = Thread(target=s3.electionTimeout)
t3.start()
# Connect the client to the cluster leader through a non-leader
c1 = Client()
c1.connectClientToLeader(s2.neighbors)
# Use the command line
c1.waitForCommands()