You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/08/14 14:36:11 UTC

[GitHub] lebeg commented on a change in pull request #12161: [WIP] A solution to prevent zombie containers locally and in CI

lebeg commented on a change in pull request #12161: [WIP] A solution to prevent zombie containers locally and in CI
URL: https://github.com/apache/incubator-mxnet/pull/12161#discussion_r209968423
 
 

 ##########
 File path: ci/build.py
 ##########
 @@ -37,11 +41,54 @@
 import platform
 from copy import deepcopy
 from itertools import chain
-from subprocess import call, check_call
+from subprocess import call, check_call, check_output
 from typing import *
 from util import *
+try:
+    pip_install('docker')
+    import docker
+    import docker.models
+    import docker.errors
+    import signal
+    import atexit
+except ImportError as e:
+    logging.error(e)
+    logging.critical("Py docker is required to run: https://pypi.org/project/docker/ it can be installed with 'pip3 install docker'")
+    sys.exit(1)
+
+
+class Cleanup:
+    def __init__(self):
+        self.containers = set()
+
+    def add_container(self, container: docker.models.containers.Container):
+        assert isinstance(container, docker.models.containers.Container)
+        self.containers.add(container)
+
+    def remove_container(self, container: docker.models.containers.Container):
+        assert isinstance(container, docker.models.containers.Container)
+        self.containers.remove(container)
+
+    def _cleanup_containers(self):
+        if self.containers:
+            logging.warning("Cleaning up containers")
+        docker_client = docker.from_env()
+        try:
+            stop_timeout = int(os.environ.get("DOCKER_STOP_TIMEOUT", 3))
+        except Exception as e:
+            stop_timeout = 3
+        for container in self.containers:
+            try:
+                container.stop(timeout=stop_timeout)
+                logging.warning("☠: %s", trim_container_id(container.id))
+            except Exception as e:
+                logging.exception(e)
 
 Review comment:
   That might be a good place for a warning

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services