我有一个用于列表中列出的多个设备的函数。如果它不能在特定设备上工作,并且脚本中断,则抛出错误。
def macGrabber(child,switch,cat = False):
try:
if cat is False:
child.expect('.#')
child.sendline('sh mac address-table | no-more')
else:
child.sendline('sh mac address-table dynamic | i Gi')
child.expect('.#', timeout=3000)
except pexpect.TIMEOUT:
print child.before,child.after
child.close()
raise
macs = child.before
child.close()
macs = macs.splitlines()
print('Connection to %s CLOSED' % switch)
return macs
-
在它进入“except”之前,我们是否可以循环它(重试多次)?或
-
如果下一个设备出现故障,我们可以跳过它并尝试下一个设备吗?