diff --git a/client/clip_client/client.py b/client/clip_client/client.py index 9a2b457c2..425f3bae7 100644 --- a/client/clip_client/client.py +++ b/client/clip_client/client.py @@ -284,19 +284,22 @@ async def aencode(self, content, **kwargs): ) results = DocumentArray() - async for da in self._async_client.post( - **self._get_post_payload(content, kwargs) - ): - if not results: - self._pbar.start_task(self._r_task) - results.extend(da) - self._pbar.update( - self._r_task, - advance=len(da), - total_size=str( - filesize.decimal(int(os.environ.get('JINA_GRPC_RECV_BYTES', '0'))) - ), - ) + with self._pbar: + async for da in self._async_client.post( + **self._get_post_payload(content, kwargs) + ): + if not results: + self._pbar.start_task(self._r_task) + results.extend(da) + self._pbar.update( + self._r_task, + advance=len(da), + total_size=str( + filesize.decimal( + int(os.environ.get('JINA_GRPC_RECV_BYTES', '0')) + ) + ), + ) return self._unboxed_result(results) @@ -415,16 +418,21 @@ async def arank(self, docs: Iterable['Document'], **kwargs) -> 'DocumentArray': total=len(docs), ) results = DocumentArray() - async for da in self._async_client.post(**self._get_rank_payload(docs, kwargs)): - if not results: - self._pbar.start_task(self._r_task) - results.extend(da) - self._pbar.update( - self._r_task, - advance=len(da), - total_size=str( - filesize.decimal(int(os.environ.get('JINA_GRPC_RECV_BYTES', '0'))) - ), - ) + with self._pbar: + async for da in self._async_client.post( + **self._get_rank_payload(docs, kwargs) + ): + if not results: + self._pbar.start_task(self._r_task) + results.extend(da) + self._pbar.update( + self._r_task, + advance=len(da), + total_size=str( + filesize.decimal( + int(os.environ.get('JINA_GRPC_RECV_BYTES', '0')) + ) + ), + ) return results