Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batchspawner/batchspawner: Fix exception handling in run_command. #195

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions batchspawner/batchspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,25 @@ async def run_command(self, cmd, input=None, env=None):
try:
out, eout = await proc.communicate(input=inbytes)
except:
self.log.debug("Exception raised when trying to run command: %s" % command)
self.log.debug("Exception raised when trying to run command: %s" % cmd)
proc.kill()
self.log.debug("Running command failed done kill")
out, eout = await proc.communicate()
out = out.decode.strip()
eout = eout.decode.strip()
self.log.error("Subprocess returned exitcode %s" % proc.returncode)
self.log.error('Stdout:')
self.log.error(out)
self.log.error('Stderr:')
self.log.error(eout)
raise RuntimeError('{} exit status {}: {}'.format(cmd, proc.returncode, eout))
self.log.debug("Running command failed, killed process.")
try:
out, eout = await asyncio.wait_for(proc.communicate(), timeout=2)
out = out.decode().strip()
eout = eout.decode().strip()
self.log.error("Subprocess returned exitcode %s" % proc.returncode)
self.log.error('Stdout:')
self.log.error(out)
self.log.error('Stderr:')
self.log.error(eout)
raise RuntimeError('{} exit status {}: {}'.format(cmd, proc.returncode, eout))
except asyncio.TimeoutError:
self.log.error('Encountered timeout trying to clean up command, process probably killed already: %s' % cmd)
return ""
except:
self.log.error('Encountered exception trying to clean up command: %s' % cmd)
raise
else:
eout = eout.decode().strip()
err = proc.returncode
Expand Down