Skip to content

Commit ee961fe

Browse files
author
William Krinsman
committed
Maybe better errorr handling/catching.
1 parent 28a7207 commit ee961fe

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

batchspawner/batchspawner.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,34 @@ async def run_command(self, cmd, input=None, env=None):
187187
if input:
188188
inbytes=input.encode()
189189

190-
out, eout = await proc.communicate(input=inbytes)
191-
192-
eout = eout.decode().strip()
193-
194-
err = proc.returncode
195-
196-
if err != 0:
197-
self.log.error("Subprocess returned exitcode %s" % err)
198-
self.log.error(eout)
199-
raise RuntimeError(eout)
190+
try:
191+
out, eout = await proc.communicate(input=inbytes)
192+
except:
193+
self.log.debug("Exception raised when trying to run command: %s" % command)
194+
proc.kill()
195+
self.log.debug("Running command failed done kill")
196+
out, eout = await proc.communicate()
197+
out = out.decode.strip()
198+
eout = eout.decode.strip()
199+
self.log.debug("Running command failed done communicate")
200+
self.log.debug("Subprocess returned exitcode %s" % proc.returncode)
201+
self.log.debug("Subprocess returned standard output %s" % out)
202+
self.log.debug("Subprocess returned standard error %s" % eout)
203+
raise
200204
else:
201-
out = out.decode().strip()
202-
return out
205+
eout = eout.decode().strip()
206+
err = proc.returncode
207+
if err != 0:
208+
self.log.error("Subprocess returned exitcode %s" % err)
209+
self.log.error(eout)
210+
raise RuntimeError(eout)
211+
212+
out = out.decode().strip()
213+
return out
203214

204215
async def _get_batch_script(self, **subvars):
205216
"""Format batch script from vars"""
206-
# Colud be overridden by subclasses, but mainly useful for testing
217+
# Could be overridden by subclasses, but mainly useful for testing
207218
return format_template(self.batch_script, **subvars)
208219

209220
async def submit_batch_script(self):

0 commit comments

Comments
 (0)