Skip to content

Commit

Permalink
Add a timeout argument to _exec_command
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirschfeld authored Jul 21, 2018
1 parent 33f981b commit c0ed6ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fs/sshfs/sshfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,18 @@ def locale(self):
self._locale = self._guess_locale()
return self._locale

def _exec_command(self, cmd):
def _exec_command(self, cmd, timeout=1):
"""Run a command on the remote SSH server.
Returns:
bytes: the output of the command, if it didn't fail
None: if the error pipe of the command was not empty
"""
_, out, err = self._client.exec_command(cmd)
return out.read().strip() if not err.read().strip() else None
_, out, err = self._client.exec_command(cmd, timeout=timeout)
try:
return out.read().strip() if not err.read().strip() else None
except socket.timeout:
return None

def _guess_platform(self):
"""Guess the platform of the remove server.
Expand Down

0 comments on commit c0ed6ab

Please sign in to comment.