Skip to content

Commit

Permalink
Let's check gc
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Jun 25, 2024
1 parent 0fe9810 commit 5d31afb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion aiodocker/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(
ssl_context: Optional[ssl.SSLContext] = None,
api_version: str = "auto",
) -> None:
self._init = False
docker_host = url # rename
if docker_host is None:
docker_host = os.environ.get("DOCKER_HOST", None)
Expand Down Expand Up @@ -166,6 +167,7 @@ def __init__(
# legacy aliases
self.pull = self.images.pull
self.push = self.images.push
self._init = True

async def __aenter__(self) -> "Docker":
return self
Expand All @@ -181,7 +183,10 @@ async def __aexit__(
async def close(self) -> None:
await self.events.stop()
await self.session.close()
await self.connector.close()

def __del__(self) -> None:
if self._init and not self.session.closed:
raise RuntimeError("A Docker instance must be explicitly closed")

async def auth(self, **credentials: Any) -> Dict[str, Any]:
response = await self._query_json("auth", "POST", data=credentials)
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import os
import sys
import traceback
Expand Down Expand Up @@ -95,6 +96,7 @@ async def docker(testing_images):
raise RuntimeError(f"Cannot find docker API version for {version}")

docker = Docker(**kwargs)
print(asyncio.get_running_loop())
try:
yield docker
finally:
Expand Down

0 comments on commit 5d31afb

Please sign in to comment.