Skip to content

Commit c5a0cf5

Browse files
committed
remove session variable
1 parent a805455 commit c5a0cf5

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

packages/toolbox-core/src/toolbox_core/sync_client.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class ToolboxSyncClient:
3232
service endpoint.
3333
"""
3434

35-
__session: Optional[ClientSession] = None
3635
__loop: Optional[asyncio.AbstractEventLoop] = None
3736
__thread: Optional[Thread] = None
3837

@@ -55,21 +54,13 @@ def __init__(
5554
self.__class__.__thread = thread
5655
self.__class__.__loop = loop
5756

58-
async def __start_session() -> None:
59-
# Use a default session if none is provided. This leverages connection
60-
# pooling for better performance by reusing a single session throughout
61-
# the application's lifetime.
62-
if self.__class__.__session is None:
63-
self.__class__.__session = ClientSession()
57+
async def create_client():
58+
return ToolboxClient(url)
6459

65-
asyncio.run_coroutine_threadsafe(
66-
__start_session(), self.__class__.__loop
60+
self.__async_client = asyncio.run_coroutine_threadsafe(
61+
create_client(), ToolboxSyncClient.__loop
6762
).result()
6863

69-
if not self.__class__.__session:
70-
raise ValueError("Session cannot be None.")
71-
self.__async_client = ToolboxClient(url, self.__class__.__session)
72-
7364
def close(self):
7465
"""
7566
Synchronously closes the underlying client session. Doing so will cause
@@ -79,7 +70,7 @@ def close(self):
7970
is responsible for its lifecycle, but calling close here will still
8071
attempt to close it.
8172
"""
82-
coro = self.__session.close()
73+
coro = self.__async_client.close()
8374
asyncio.run_coroutine_threadsafe(coro, self.__loop).result()
8475

8576
def load_tool(

0 commit comments

Comments
 (0)