Skip to content
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

Add timeout to SSH queue scan command #191

Merged
merged 11 commits into from
Jun 18, 2024
21 changes: 14 additions & 7 deletions sisyphus/simple_linux_utility_for_resource_management_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,23 @@ def system_call(self, command, send_to_stdin=None):
"""
if self.gateway:
escaped_command = [shlex.quote(s) for s in command] # parameters need to be shell safe when sending via ssh
system_command = ["ssh", "-x", self.gateway] + [" ".join(["cd", os.getcwd(), "&&"] + escaped_command)]
system_command = ["ssh", "-x", self.gateway, "-o", "BatchMode=yes"] + [
" ".join(["cd", os.getcwd(), "&&"] + escaped_command)
]
else:
# no gateway given, skip ssh local
system_command = command

logging.debug("shell_cmd: %s" % " ".join(system_command))
p = subprocess.Popen(system_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if send_to_stdin:
send_to_stdin = send_to_stdin.encode()
out, err = p.communicate(input=send_to_stdin, timeout=30)
p = subprocess.run(
system_command,
stdin=send_to_stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=gs.WAIT_PERIOD_BETWEEN_CHECKS,
)
Icemole marked this conversation as resolved.
Show resolved Hide resolved

def fix_output(o):
"""
Expand All @@ -109,9 +116,9 @@ def fix_output(o):
assert False
return o[:-1]

out = fix_output(out)
err = fix_output(err)
retval = p.wait(timeout=30)
out = fix_output(p.stdout)
err = fix_output(p.stderr)
retval = p.returncode

# Check for ssh error
err_ = []
Expand Down Expand Up @@ -289,7 +296,7 @@ def reset_cache(self):
def queue_state(self):
"""Returns list with all currently running tasks in this queue"""

if time.time() - self._task_info_cache_last_update < 30:
if time.time() - self._task_info_cache_last_update < gs.WAIT_PERIOD_BETWEEN_CHECKS:
# use cached value
return self._task_info_cache

Expand Down
21 changes: 14 additions & 7 deletions sisyphus/son_of_grid_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,23 @@ def system_call(self, command, send_to_stdin=None):
:rtype: list[bytes], list[bytes], int
"""
if self.gateway:
system_command = ["ssh", "-x", self.gateway] + [" ".join(["cd", os.getcwd(), "&&"] + command)]
system_command = ["ssh", "-x", self.gateway, "-o", "BatchMode=yes"] + [
" ".join(["cd", os.getcwd(), "&&"] + command)
]
else:
# no gateway given, skip ssh local
system_command = command

logging.debug("shell_cmd: %s" % " ".join(system_command))
p = subprocess.Popen(system_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if send_to_stdin:
send_to_stdin = send_to_stdin.encode()
out, err = p.communicate(input=send_to_stdin, timeout=30)
p = subprocess.run(
system_command,
stdin=send_to_stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=gs.WAIT_PERIOD_BETWEEN_CHECKS,
)

def fix_output(o):
"""
Expand All @@ -110,9 +117,9 @@ def fix_output(o):
assert False
return o[:-1]

out = fix_output(out)
err = fix_output(err)
retval = p.wait(timeout=30)
out = fix_output(p.stdout)
err = fix_output(p.stderr)
retval = p.returncode

# Check for ssh error
err_ = []
Expand Down Expand Up @@ -307,7 +314,7 @@ def reset_cache(self):
def queue_state(self):
"""Return s list with all currently running tasks in this queue"""

if time.time() - self._task_info_cache_last_update < 30:
if time.time() - self._task_info_cache_last_update < gs.WAIT_PERIOD_BETWEEN_CHECKS:
# use cached value
return self._task_info_cache

Expand Down
Loading