Skip to content

Commit

Permalink
fix: RuntimeWarning: coroutine 'Channel.close' was never awaited when…
Browse files Browse the repository at this point in the history
… closing async client (#2497)

Signed-off-by: Ruichen Bao <[email protected]>
  • Loading branch information
brcarry authored Dec 23, 2024
1 parent 506ba36 commit b5a9626
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pymilvus/client/async_grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def __enter__(self):
def __exit__(self: object, exc_type: object, exc_val: object, exc_tb: object):
pass

def close(self):
async def close(self):
self.deregister_state_change_callbacks()
self._async_channel.close()
await self._async_channel.close()

def _setup_authorization_interceptor(self, user: str, password: str, token: str):
keys = []
Expand Down
4 changes: 2 additions & 2 deletions pymilvus/milvus_client/async_milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ def create_schema(cls, **kwargs):
kwargs["check_fields"] = False # do not check fields for now
return CollectionSchema([], **kwargs)

def close(self):
connections.disconnect(self._using)
async def close(self):
await connections.async_disconnect(self._using)

def _get_connection(self):
return connections._fetch_handler(self._using)
Expand Down
7 changes: 7 additions & 0 deletions pymilvus/orm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ def disconnect(self, alias: str):
if alias in self._connected_alias:
self._connected_alias.pop(alias).close()

async def async_disconnect(self, alias: str):
if not isinstance(alias, str):
raise ConnectionConfigException(message=ExceptionsMessage.AliasType % type(alias))

if alias in self._connected_alias:
await self._connected_alias.pop(alias).close()

def remove_connection(self, alias: str):
"""Removes connection from the registry.
Expand Down

0 comments on commit b5a9626

Please sign in to comment.