From b0463e58d892c25a89deae3e361486f05158ef4d Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Mon, 20 Aug 2018 11:15:48 +0100 Subject: [PATCH] ssh: Use atexit to automatically close ssh connections As stated in https://github.com/ARM-software/devlib/issues/308 devlib can leave ssh connections open after they are no longer in use, so now register the close method with atexit so the connections are no longer left open upon exit. --- devlib/utils/ssh.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devlib/utils/ssh.py b/devlib/utils/ssh.py index 6b87025..5e1eb10 100644 --- a/devlib/utils/ssh.py +++ b/devlib/utils/ssh.py @@ -25,6 +25,7 @@ import shutil import socket import sys import time +import atexit # pylint: disable=import-error,wrong-import-position,ungrouped-imports,wrong-import-order import pexpect @@ -181,6 +182,7 @@ class SshConnection(object): logger.debug('Logging in {}@{}'.format(username, host)) timeout = timeout if timeout is not None else self.default_timeout self.conn = ssh_get_shell(host, username, password, self.keyfile, port, timeout, False, None) + atexit.register(self.close) def push(self, source, dest, timeout=30): dest = '"{}"@"{}":"{}"'.format(escape_double_quotes(self.username),