Skip to content
Snippets Groups Projects
Commit 842ff9c2 authored by Anael Beutot's avatar Anael Beutot
Browse files

Handles SIGCHLD for remote shell

parent 13fc5780
No related branches found
No related tags found
No related merge requests found
......@@ -90,6 +90,7 @@ class RemoteShell(object):
self.proto = conn.create_tunnel(endpoint=self.endpoint,
on_shutdown=self.on_tunnel_shutdown)
self.conn = conn
self.child_watcher = None
try:
self.process = subprocess.Popen(
[exec_], stdout=self.slave,
......@@ -104,6 +105,9 @@ class RemoteShell(object):
# close opened fds
self.close_cb()
raise
self.child_watcher = conn.loop.child(self.process.pid, False,
self.child_cb)
self.child_watcher.start()
@property
def label(self):
......@@ -121,11 +125,18 @@ class RemoteShell(object):
self.close()
logger.debug('Tunnel closed by sjRPC')
def child_cb(self, watcher, revents):
logger.debug('Tunnel closed by process termination')
self.process.returncode = watcher.rstatus
self.close()
def close(self):
if self.process.poll() is None:
if self.child_watcher is not None:
self.child_watcher.stop()
self.child_watcher = None
if self.process.returncode is None:
# process is still alive
self.process.kill()
self.process.wait()
if self.master is not None:
try:
os.close(self.master)
......
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