python 多线程 运维问题, 详见问题补充 我写了一段代码 但感觉有问题,希望大侠能指点。

2025-03-24 10:20:36
推荐回答(1个)
回答(1):

你这个脚本有些语法问题,不过总的设计思路是没有问题的。 我已经用你的脚本执行了,输入如下。我觉得可以讲hosts.txt文件拆分成5个文件,每个文件含8条ip,按顺序执行,这样可以控制每次只处理8个ip,也就达到并发8台机子的要求。

python multhred.py "echo 'hello world'"
Please input password:
current has 1 threads
current has 3 threads
current has 4 threads
current has 6 threads
current has 8 threads
current has 11 threads
current has 12 threads
current has 14 threads
hello world
172.***.***.*** OK

hello world
172.***.***.*** OK

hello world
172.***.***.*** OK

hello world
172.***.***.*** OK

hello world
172.***.***.*** OK

hello world
172.***.***.*** OK

hello world
172.***.***.*** OK

hello world
172.***.***.*** OK