Skip to content

Commit d32e089

Browse files
committed
Fix linting errors and add logging.
1 parent faf48cc commit d32e089

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

testcontainers/core/cleaner.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

testcontainers/core/docker_client.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@
1414
import os
1515
import urllib
1616
import docker
17+
from docker.errors import NotFound
1718
from docker.models.containers import Container
1819

19-
from testcontainers.core.cleaner import stop_silent
2020
from testcontainers.core.utils import inside_container
2121
from testcontainers.core.utils import default_gateway_ip
22+
from testcontainers.core.utils import setup_logger
23+
24+
25+
LOGGER = setup_logger(__name__)
26+
27+
28+
def _stop_container(container):
29+
try:
30+
container.stop()
31+
except NotFound:
32+
pass
33+
except Exception as ex:
34+
LOGGER.warning("failed to shut down container %s with image %s: %s", container.id,
35+
container.image, ex)
2236

2337

2438
class DockerClient(object):
@@ -34,15 +48,15 @@ def run(self, image: str,
3448
stderr: bool = False,
3549
remove: bool = False, **kwargs) -> Container:
3650
container = self.client.containers.run(image,
37-
command=command,
38-
stdout=stdout,
39-
stderr=stderr,
40-
remove=remove,
41-
detach=detach,
42-
environment=environment,
43-
ports=ports,
44-
**kwargs)
45-
atexit.register(stop_silent, container)
51+
command=command,
52+
stdout=stdout,
53+
stderr=stderr,
54+
remove=remove,
55+
detach=detach,
56+
environment=environment,
57+
ports=ports,
58+
**kwargs)
59+
atexit.register(_stop_container, container)
4660

4761
return container
4862

0 commit comments

Comments
 (0)