Add exit handling

os-repl
root 2022-11-29 19:22:27 +00:00
parent d17ecc9806
commit b884a180c8
1 changed files with 16 additions and 7 deletions

View File

@ -80,32 +80,41 @@ class Runner(threading.Thread):
if self.shell_channel in r: if self.shell_channel in r:
x = self.shell_channel.recv(1024) x = self.shell_channel.recv(1024)
if len(x) == 0: if len(x) == 0:
break self.shell_channel = None
client_shell_channel.send(x) client_shell_channel.send(x)
if client_shell_channel in r: if client_shell_channel in r:
x = client_shell_channel.recv(1024) x = client_shell_channel.recv(1024)
if len(x) == 0: if len(x) == 0:
break self.shell_channel = None
self.shell_channel.send(x) self.shell_channel.send(x)
if self.sftp_channel is not None: # TODO: move this to function if self.sftp_channel is not None: # TODO: move this to function
r, w, e = select.select([client_sftp_channel, self.sftp_channel], [], []) r, w, e = select.select([client_sftp_channel, self.sftp_channel], [], [])
if self.sftp_channel in r: if self.sftp_channel in r:
x = self.sftp_channel.recv(1024) x = self.sftp_channel.recv(1024)
if len(x) == 0: if len(x) == 0:
break self.sftp_channel = None
client_sftp_channel.send(x) client_sftp_channel.send(x)
if client_sftp_channel in r: if client_sftp_channel in r:
x = client_sftp_channel.recv(1024) x = client_sftp_channel.recv(1024)
if len(x) == 0: if len(x) == 0:
break self.sftp_channel = None
self.sftp_channel.send(x) self.sftp_channel.send(x)
if self.transport.is_active() is False: if self.transport.is_active() is False:
break break
client_shell_channel.close() try:
self.shell_channel.close() client_shell_channel.close()
self.shell_channel.close()
except AttributeError as e:
logger.debug(e)
try:
client_sftp_channel.close()
self.sftp_channel.close()
except AttributeError as e:
logger.debug(e)
lxd_interface.destroy_instance(self.instance_name) lxd_interface.destroy_instance(self.instance_name)
def set_shell_channel(self, channel): def set_shell_channel(self, channel):