diff --git a/README.rst b/README.rst index fb4abfe..b4c87b4 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ CondorPy ======== :condorpy: Python interface for high throughput computing with HTCondor -:Version: 0.5.1 +:Version: 0.5.2 :Author: Scott Christensen :Team: Tethys Platform :Homepage: http://tethysplatform.org/condorpy/ diff --git a/condorpy/remote_utils.py b/condorpy/remote_utils.py index 774877a..e446c9a 100644 --- a/condorpy/remote_utils.py +++ b/condorpy/remote_utils.py @@ -23,6 +23,9 @@ def __init__(self, self._scp = None self._sftp = None + def __del__(self): + self.close() + @property def transport(self): if self._transport is None or not self._transport.is_active(): @@ -52,13 +55,17 @@ def _get_output(self, session): return stdout, stderr def execute(self, command): - session = self.transport.open_session() - session.exec_command(command) - stdout, stderr = self._get_output(session) - exit_status = session.recv_exit_status() - if exit_status != 0: - msg = "The command '{0}' failed on host '{1}':\n{2}\n{3}".format(command, self.host, stdout, stderr) - raise RuntimeError(msg) + session = None + try: + session = self.transport.open_session() + session.exec_command(command) + stdout, stderr = self._get_output(session) + exit_status = session.recv_exit_status() + if exit_status != 0: + msg = "The command '{0}' failed on host '{1}':\n{2}\n{3}".format(command, self.host, stdout, stderr) + raise RuntimeError(msg) + finally: + session and session.close() return stdout, stderr