因为在作自动化部署时,希望能将多个服务分不同的批次进行发布,
同一批次的机器同时发布,
如果前面一批次出错误,后面就需要停止整 个流程。
那可以简单的用threading来实现了。
thread_list = list()
for i in range(0, len(item)):
thread_name = "thread_%s" % i
thread_list.append(threading.Thread(target=cmd_run,
name=thread_name,
args=(item[i],
deployversion_id,
deploy_type,
cmd,
current_user_set,
percent_value)))
for thread in thread_list:
thread.start()
for thread in thread_list:
thread.join()