I am reading some output of remote server using SSH bash(command
). I need to do it constantly, so I spawn subprocess. It works fine, unless server server become unavailable for brief period.
How do I restart SSH command (whole subprocess) if it fails?
I have following piece of code:
(...)
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
(...)
I would think that process.poll() is not None
should do the trick
but it seems to hang on
1000 21431 0.0 0.0 0 0 pts/0 Z+ Oct22 0:00 [ssh] <defunct>
And does not break out of while True: