本文整理汇总了Python中Server.Server.add_server_to_network方法的典型用法代码示例。如果您正苦于以下问题:Python Server.add_server_to_network方法的具体用法?Python Server.add_server_to_network怎么用?Python Server.add_server_to_network使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Server
的用法示例。
在下文中一共展示了Server.add_server_to_network方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PiggyNetwork
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import add_server_to_network [as 别名]
class PiggyNetwork():
host = '127.0.0.1'
base_port = 50000
base_data_path = "/primary_data.txt"
base_backup_path = "/backup_data.txt"
# Defining the workload per server. In this case clients with last names A-M are processed by server 1 #
# and clients with last names N-Z are processed by server 2 #
total_workload = list(string.ascii_uppercase)
# Initialize our Network with two servers, with divided workloads, and their relevant data paths. Each server is then #
# added to the other's detectable network #
def __init__(self):
self.server1 = Server(self.base_port, self.total_workload[:14], "server1" + self.base_data_path, "server1" + self.base_backup_path)
self.server2 = Server(self.base_port + 1, self.total_workload[14:], "server2" + self.base_data_path, "server2" + self.base_backup_path)
self.server1.add_server_to_network(self.server2)
self.server2.add_server_to_network(self.server1)
# Getters #
def get_server1(self):
return self.server1
def get_server2(self):
return self.server2
# End Getters #
# Multi-Threaded Functionality #
def boot_server(self, server):
server.listen()
def initialize(self):
thread1 = threading.Thread(target=self.boot_server, args=(self.server1,))
thread2 = threading.Thread(target=self.boot_server, args=(self.server2,))
thread1.start()
thread2.start()