Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Sep 22, 2023
1 parent 34dd1be commit 5131f01
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ def close_client(client: httpx.Client) -> None:
client : client
The httpx client to close.
"""
if client.is_closed:
return
logger.debug("Closing Client._client")
client.close()


def close_async_client(client: httpx.AsyncClient) -> None:
logger.debug("Closing Client._aclient")
if client.is_closed:
return
coro = client.aclose()
try:
# Raises RuntimeError if there is no current event loop.
Expand All @@ -144,12 +148,12 @@ def close_async_client(client: httpx.AsyncClient) -> None:
# running coroutine, which we cannot interrupt to run this one.
# The solution is to create a new loop in a new thread.
with concurrent.futures.ThreadPoolExecutor(1) as executor:
executor.submit(_run_coros, coro).result()
executor.submit(_run_coro, coro).result()
else:
_run_coros(coro)
_run_coro(coro)


def _run_coros(coro: Coroutine) -> None:
def _run_coro(coro: Coroutine) -> None:
if hasattr(asyncio, "Runner"):
# Python 3.11+
# Run the coroutines in a new event loop, taking care to
Expand Down

0 comments on commit 5131f01

Please sign in to comment.