bugfix: start locust slave on other machines

This commit is contained in:
debugtalk
2018-01-16 16:30:24 +08:00
parent 389e915a09
commit 25539414a2
+10 -3
View File
@@ -54,12 +54,16 @@ def start_master(sys_argv):
main() main()
def start_slave(sys_argv): def start_slave(sys_argv):
sys_argv.extend(["--slave"]) if "--slave" not in sys_argv:
sys_argv.extend(["--slave"])
sys.argv = sys_argv sys.argv = sys_argv
main() main()
def run_locusts_on_cpu_cores(sys_argv, cpu_cores_num_value): def run_locusts_on_cpu_cores(sys_argv, cpu_cores_num_value):
processes = [] processes = []
manager = multiprocessing.Manager()
for _ in range(cpu_cores_num_value): for _ in range(cpu_cores_num_value):
p_slave = multiprocessing.Process(target=start_slave, args=(sys_argv,)) p_slave = multiprocessing.Process(target=start_slave, args=(sys_argv,))
p_slave.daemon = True p_slave.daemon = True
@@ -67,6 +71,9 @@ def run_locusts_on_cpu_cores(sys_argv, cpu_cores_num_value):
processes.append(p_slave) processes.append(p_slave)
try: try:
start_master(sys_argv) if "--slave" in sys_argv:
[process.join() for process in processes]
else:
start_master(sys_argv)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit(0) manager.shutdown()