本文整理汇总了Python中server.Server.set_group方法的典型用法代码示例。如果您正苦于以下问题:Python Server.set_group方法的具体用法?Python Server.set_group怎么用?Python Server.set_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.Server
的用法示例。
在下文中一共展示了Server.set_group方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import set_group [as 别名]
def main():
main_server_instance = Server(HOST, user=USER, passwd=PASSWD, port=PORT, use_ssl=USE_SSL)
manager = multiprocessing.Manager()
lock = multiprocessing.Lock()
for group in GROUPS:
workers = []
# get group info here.
first, last, count = main_server_instance.set_group(group)
start_index = multiprocessing.Value('i', last)
results = manager.list()
args = (HOST, USER, PASSWD, PORT, USE_SSL, group, start_index,
CHUNK_SIZE, results, lock, first)
for i in range(1, MAX_CONNECTIONS):
p = multiprocessing.Process(target=article_worker, args=args)
p.start()
workers.append(p)
try:
for worker in workers:
worker.join()
except KeyboardInterrupt:
for worker in workers:
worker.terminate()
worker.join()
for worker in workers:
worker.terminate()
worker.join()
print(first, start_index.value, last)
示例2: article_worker
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import set_group [as 别名]
def article_worker(host, user, passwd, port, use_ssl, group, start_index,
chunk_size, results, lock, min_index):
signal.signal(signal.SIGINT, signal.SIG_IGN)
s = Server(host, user, passwd, port, use_ssl)
s.set_group(group)
while start_index.value > min_index:
# increment start_index here so no two processes end up pulling the same data
with lock:
if start_index.value < min_index:
continue
upper_limit = start_index.value
lower_limit = start_index.value - chunk_size
start_index.value = (start_index.value - chunk_size + 1)
if lower_limit < min_index:
lower_limit = min_index
results.append(s.fetch_articles(group, lower_limit, upper_limit))
# close the connection here so we can process another group
s.quit()