我正在使用SSH bash(command
)阅读远程服务器的一些输出。我需要不断地进行操作,因此会生成子流程。除非服务器服务器在短时间内不可用,否则它将正常工作。如果失败,如何重新启动SSH命令(整个子进程)?
我有以下代码:
(...)
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
while True:
line = process.stdout.readline()
if lines == "" and process.poll() is not None:
break
(...)
我认为process.poll() is not None
应该可以解决问题,但似乎仍会持续
1000 21431 0.0 0.0 0 0 pts/0 Z+ Oct22 0:00 [ssh] <defunct>
并且不爆发 while True:
我的代码中有愚蠢的错字错误,if lines == "" and process.poll() is not None:
无法正常执行。另一件事要看的是ssh_config,明智的做法是将值设置为断开@ 60秒/ 1次尝试。并避免使用process.communicate(),因为它会阻塞整个线程。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句