@@ -32,7 +32,6 @@ class ToolboxSyncClient:
32
32
service endpoint.
33
33
"""
34
34
35
- __session : Optional [ClientSession ] = None
36
35
__loop : Optional [asyncio .AbstractEventLoop ] = None
37
36
__thread : Optional [Thread ] = None
38
37
@@ -55,21 +54,13 @@ def __init__(
55
54
self .__class__ .__thread = thread
56
55
self .__class__ .__loop = loop
57
56
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 )
64
59
65
- asyncio .run_coroutine_threadsafe (
66
- __start_session (), self . __class__ .__loop
60
+ self . __async_client = asyncio .run_coroutine_threadsafe (
61
+ create_client (), ToolboxSyncClient .__loop
67
62
).result ()
68
63
69
- if not self .__class__ .__session :
70
- raise ValueError ("Session cannot be None." )
71
- self .__async_client = ToolboxClient (url , self .__class__ .__session )
72
-
73
64
def close (self ):
74
65
"""
75
66
Synchronously closes the underlying client session. Doing so will cause
@@ -79,7 +70,7 @@ def close(self):
79
70
is responsible for its lifecycle, but calling close here will still
80
71
attempt to close it.
81
72
"""
82
- coro = self .__session .close ()
73
+ coro = self .__async_client .close ()
83
74
asyncio .run_coroutine_threadsafe (coro , self .__loop ).result ()
84
75
85
76
def load_tool (
0 commit comments