Python3 paramiko内存错误与大型stdout数据

时间:2015-07-15 15:30:30

标签: python python-3.x memory paramiko

我正在使用paramiko库ssh到路由器并运行sh操作命令,其中输出非常大(> 500MB),并且它会引发内存错误。有没有办法重新编写我的代码,因此它不会将所有数据都放入内存并引发错误。

stdin, stdout, stderr = ssh_session.execute_command(' '.join(['show operational',request,'xml'])) #request is just a str represnting the differnet components (AAA, etc.)
process_output(''.join(stdout.readlines()),request) #stdout.readlines() is what causes the memory error
ssh_session.close()

错误:

polling IPV6_RIB
Exception: Expecting packet from (31,), got 94
Traceback (most recent call last):
  File "/home/lab/5.3.2_xml/py3/lib/python3.4/site-packages/paramiko/transport.py", line 1607, in run
    raise SSHException('Expecting packet from %r, got %d' % (self._expected_packet, ptype))
paramiko.ssh_exception.SSHException: Expecting packet from (31,), got 94

Traceback (most recent call last):
  File "xml_oper.py", line 42, in <module>
    main()
  File "xml_oper.py", line 37, in main
    process_output(''.join(stdout.readlines()),request)
MemoryError

0 个答案:

没有答案