Skip to content

Commit

Permalink
Merge pull request #34 from Aquaveo/connection_leak_bugfix
Browse files Browse the repository at this point in the history
Connection Leak Bugfix
  • Loading branch information
swainn authored Sep 5, 2019
2 parents a5aaaef + b29e2a9 commit 3eaf089
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
21 changes: 14 additions & 7 deletions condorpy/remote_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 3eaf089

Please sign in to comment.