首页 > 代码库 > 为每台服务器分配相等数量的关键字列表

为每台服务器分配相等数量的关键字列表

 1 def kw_to_ervery_server(kw,server_total,server_num=1): 2     ‘‘‘ 3         @kw 是数据库读取的关键字列表 4         @server_total 服务器台数 5         @server_num 是服务器编号第一台服务器编号是1,第二台就是2,依次类推 6         @注意:server_num  < server_total and server_num  > 0 7          8     ‘‘‘ 9     if server_num == 0:10         server_num = 111     if (server_num <= 0) or (server_num > server_total):12         print server_num must be < server_total or server_num must > zero13         return14     len_kw = len(kw) #关键词15     num_list = []16     n1 = int(len_kw/server_total)17     i = 018     n_next = 019     while i <= server_total:20         if i == server_total:21             n_next = len_kw22         num_list.append(n_next)23         n_next += n124         i += 1 25     kw_list=kw[num_list[server_num-1]:num_list[server_num]] #每台服务器的关键字列表26 27     return kw_list28 29 30 if __name__ == __main__:31     kw = range(110)32     server_total = 1033     server_num = 034     kw = kw_to_ervery_server(kw,server_total)35     print kw

 

为每台服务器分配相等数量的关键字列表