我试图使用Pexpect async expect(python3.5.1和github中的Pexpect)编写脚本,从网络设备收集一些信息,但得到了一些奇怪的东西:所有这些都可以在多个设备上正常工作,而不能在更多设备上工作(通常是5-6)。我写了这个简单的测试脚本:@asyncio.coroutine
def test_ssh_expect_async(num):
print('Task #{0} start'.format(num))
p = pexpect.spawn('ssh localhost', encoding='utf8')
#p.logfile = sys.stdout
yield from p.expect('password', async=True)
p.sendline('***')
yield from p.expect(r'@self-VirtualBox\:', async=True)
p.sendline('uptime')
yield from p.expect(r'@self-VirtualBox\:', async=True)
p.sendline('uname -a')
yield from p.expect(r'@self-VirtualBox\:', async=True)
p.sendline('ll')
yield from p.expect(r'@self-VirtualBox\:', async=True)
print('Task