Skip to content
Snippets Groups Projects
Commit a0db555e authored by Chris Hines's avatar Chris Hines
Browse files

put a timeout on executing things via ssh

parent ad1f596a
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ This module handles SSH Connections
"""
import subprocess
TIMEOUT=10
class SshAgentException(Exception):
"""
Raised if an SSH Agent isn't running (Normally the SPA client should invoke the agent
......@@ -270,10 +271,15 @@ class Ssh:
'-p', sshport, '-l', user, host, cmd],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE, env=env)
if stdin is not None:
(stdout, stderr) = exec_p.communicate(stdin.encode())
else:
try:
if stdin is not None:
(stdout, stderr) = exec_p.communicate(stdin.encode(),timeout=TIMEOUT)
else:
(stdout, stderr) = exec_p.communicate(timeout=TIMEOUT)
except subprocess.TimeoutExpired:
exec_p.kill()
(stdout, stderr) = exec_p.communicate()
return {'stdout':stdout, 'stderr':stderr}
@staticmethod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment