Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Sep 28, 2023
1 parent 4ec8869 commit 193924b
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def close_async_client(client: httpx.AsyncClient) -> None:
return
try:
with concurrent.futures.ThreadPoolExecutor(1) as executor:
executor.submit(_close_client_in_new_thread, client).result(timeout=10)
executor.submit(lambda: asyncio.run(client.aclose())).result(timeout=10)
except concurrent.futures.TimeoutError:
logger.error("Timeout while trying to close async client")
except RuntimeError as e:
Expand All @@ -163,17 +163,6 @@ def close_async_client(client: httpx.AsyncClient) -> None:
raise


def _close_client_in_new_thread(client: httpx.AsyncClient) -> None:
new_loop = asyncio.new_event_loop()
asyncio.set_event_loop(new_loop)
try:
new_loop.run_until_complete(client.aclose())
except Exception as e:
logger.error(f"Failed to close async client: {e}")
finally:
new_loop.close()


def _validate_api_key_if_hosted(api_url: str, api_key: Optional[str]) -> None:
"""Verify API key is provided if url not localhost.
Expand Down Expand Up @@ -1919,7 +1908,7 @@ async def alist_datasets(
dataset_name=dataset_name,
dataset_name_contains=dataset_name_contains,
)
res = await self._aget_paginated_list("/datasets", params=params)
res = self._aget_paginated_list("/datasets", params=params)
async for dataset in res:
yield ls_schemas.Dataset(**dataset, _host_url=self._host_url)

Expand Down

0 comments on commit 193924b

Please sign in to comment.