Skip to content

Add a timeout argument to _exec_command #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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