【发布时间】:2022-01-17 03:29:21
【问题描述】:
我正在尝试根据我提供的 IP 列表优化连接到某些路由器的脚本。
但是,一旦完成前一个路由器,开始配置一次,完成配置需要很长时间,我的问题是,是否可以创建一个不需要等待的函数,也许是多线程功能,可以同时配置几个元素。
def configure_routers():
hosts = create_vrdc_dic() # -> it's the dictonary that pass the variables
for i in hosts .keys():
hostname = hosts [i].get('hostname')
mgmt_ip = hosts [i].get('mgmt_ip')
console_config.config_vrdc(hostname, mgmt_ip) # -> here I'm calling another module that configures the routers using pexpect
感谢您的帮助。
【问题讨论】:
-
您是如何处理这些故障的?如果您只是将它们打印到屏幕上,则消息可能是交错的。如果存在阻塞读取,它可能会永远留在那里。
-
嗨,不,我不只是打印它。基本上,我收到IP,调用另一个python模块来连接和配置路由器,所以我的想法是同时配置2个或3个,所以我不需要配置等待它完成,然后去第二个元素等
标签: python python-3.x