Permalink
Browse files

Fix Docker Freezing (#153)

* Fix #151 Docker Freezing

* Use timeout to replace blocking sleep

* Remove unnecessary import
  • Loading branch information...
rnehra01 authored and afeena committed Jun 17, 2017
1 parent e64aba8 commit 9e20f5b880f9080e0d961ef3ae725519a25a9485
Showing with 8 additions and 2 deletions.
  1. +8 −2 tanner/emulators/cmd_exec.py
@@ -1,6 +1,7 @@
import asyncio
import docker
import yarl
import concurrent
# TODO : Replace docker with aiodocker
import logging
@@ -51,10 +52,15 @@ def __init__(self):
return container
async def get_cmd_exec_results(self, container, cmd):
execute_result = None
execute_result = ''
try:
container.start()
execute_result = container.exec_run(['sh', '-c', cmd]).decode('utf-8')
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
cmd_future = executor.submit(container.exec_run, ['sh', '-c', cmd])
try:
execute_result = cmd_future.result(timeout= 1).decode('utf-8')
except concurrent.futures.TimeoutError as timeout_error:
self.logger.error('Error while executing %s in container %s', cmd, timeout_error)
container.kill()
except docker.errors.APIError as server_error:
self.logger.error('Error while executing command %s in container %s', cmd, server_error)

0 comments on commit 9e20f5b

Please sign in to comment.