Skip to content

Commit

Permalink
Add a '_DetachedProxyCommand' class which wraps paramiko.ProxyCommand
Browse files Browse the repository at this point in the history
and modifies it such that the process running the proxycommand is
shielded from signals.
  • Loading branch information
greschd authored and sphuber committed Apr 10, 2018
1 parent d424c8a commit 00ed7f6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion aiida/transport/plugins/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def open(self):
connection_arguments = self._connect_args
proxystring = connection_arguments.pop('proxy_command', None)
if proxystring is not None:
proxy = paramiko.ProxyCommand(proxystring)
proxy = _DetachedProxyCommand(proxystring)
connection_arguments['sock'] = proxy

try:
Expand Down Expand Up @@ -1403,3 +1403,16 @@ def path_exists(self, path):
raise
else:
return True


class _DetachedProxyCommand(paramiko.ProxyCommand):
"""
Modifies paramiko's ProxyCommand by launching the process in a separate process group.
"""

def __init__(self, command_line):
from subprocess import Popen, PIPE
from shlex import split as shlsplit
self.cmd = shlsplit(command_line)
self.process = Popen(self.cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=0, preexec_fn=os.setpgrp)
self.timeout = None

0 comments on commit 00ed7f6

Please sign in to comment.