fix docker container return values
@@ -255,18 +255,27 @@ def run_docker(definition, dataset, count, runs, timeout, batch, cpu_limit,
t.start()
try:
- exit_code = container.wait(timeout=timeout)
-
- # Exit if exit code
- try:
- exit_code = exit_code.StatusCode
- except AttributeError:
- pass
- if exit_code not in [0, None]:
- logger.error(colors.color(container.logs().decode(), fg='red'))
- logger.error('Child process for container %s raised exception %d' % (container.short_id, exit_code))
+ return_value = container.wait(timeout=timeout)
+ _handle_container_return_value(return_value, container)
except:
logger.error('Container.wait for container %s failed with exception' % container.short_id)
traceback.print_exc()
finally:
container.remove(force=True)
+
+
+def _handle_container_return_value(return_value, container, logger):
+ base_msg = 'Child process for container %s' % (container.short_d)
+ if type(return_value) is dict: # The return value from container.wait changes from int to dict in docker 3.0.0
+ error_msg = return_value['Error']
+ exit_code = return_value['StatusCode']
+ msg = base_msg + 'returned exit code %d with message %s' %(exit_code, error_msg)
+ else:
+ exit_code = return_value
+ msg = base_msg + 'returned exit code %d' % (exit_code)
+
+ if exit_code not in [0, None]:
+ logger.error(colors.color(container.logs().decode(), fg='red'))
+ logger.error(msg)
+
+
