延迟multiprocessing.dummy python

时间:2019-03-21 08:05:41

标签: python python-multiprocessing paramiko

我正在使用netmiko lib进行多重处理。 我想在多处理中调用connect函数之间引入一些延迟。 目前,当我使用脚本时,它同时连接到4个路由器。 我试图在连接函数中使用随机的time.sleep间隔,但这不起作用。

from multiprocessing.dummy import Pool as ThreadPool
from time import sleep
from random import randint
from netmiko import ConnectHandler




IP = [line.strip() for line in open(ip-add.txt, 'r')]

def connect(IP):
    sleep(randint(1,5)) 
    try:
        device_params = {'device_type': 'ios_xe',
                        'ip': IP,
                        'username':USER,
                        'password':PASSWORD,
                        'verbose': True}
        with ConnectHandler(**device_params) as conn:


            result = conn.send_command(COMMAND)


pool = ThreadPool(4)
results = pool.map(connect, IP)
pool.close()
pool.join()

0 个答案:

没有答案