Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions qdrant_client/async_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ async def recover_shard_snapshot(
async def close(self, **kwargs: Any) -> None:
pass

@property
def closed(self) -> bool:
"""Whether close() has been called on this client."""
return False

def migrate(
self,
dest_client: "AsyncQdrantBase",
Expand Down
9 changes: 9 additions & 0 deletions qdrant_client/async_qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ def __init__(
is_local_mode=isinstance(self._client, AsyncQdrantLocal),
)

@property
def closed(self) -> bool:
"""Whether the connection to Qdrant has been closed

Returns:
True once close() has been called, False otherwise
"""
return self._client.closed

async def close(self, grpc_grace: float | None = None, **kwargs: Any) -> None:
"""Closes the connection to Qdrant

Expand Down
5 changes: 5 additions & 0 deletions qdrant_client/client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ def recover_shard_snapshot(
def close(self, **kwargs: Any) -> None:
pass

@property
def closed(self) -> bool:
"""Whether close() has been called on this client."""
return False

def migrate(
self,
dest_client: "QdrantBase",
Expand Down
9 changes: 9 additions & 0 deletions qdrant_client/qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ def __init__(
def __del__(self) -> None:
self.close()

@property
def closed(self) -> bool:
"""Whether the connection to Qdrant has been closed

Returns:
True once close() has been called, False otherwise
"""
return self._client.closed

def close(self, grpc_grace: float | None = None, **kwargs: Any) -> None:
"""Closes the connection to Qdrant

Expand Down
53 changes: 53 additions & 0 deletions tests/test_closed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest

from qdrant_client import AsyncQdrantClient, QdrantClient


def test_local_client_reports_closed_state():
client = QdrantClient(":memory:")
assert client.closed is False

client.close()
assert client.closed is True


def test_persistent_local_client_reports_closed_state(tmp_path):
client = QdrantClient(path=str(tmp_path / "storage"))
assert client.closed is False

client.close()
assert client.closed is True


def test_remote_client_reports_closed_state():
client = QdrantClient("localhost", port=6333, check_compatibility=False)
assert client.closed is False

client.close()
assert client.closed is True


def test_closed_matches_the_inner_client():
client = QdrantClient(":memory:")
assert client.closed is client._client.closed

client.close()
assert client.closed is client._client.closed


@pytest.mark.asyncio
async def test_async_local_client_reports_closed_state():
client = AsyncQdrantClient(":memory:")
assert client.closed is False

await client.close()
assert client.closed is True


@pytest.mark.asyncio
async def test_async_remote_client_reports_closed_state():
client = AsyncQdrantClient("localhost", port=6333, check_compatibility=False)
assert client.closed is False

await client.close()
assert client.closed is True