@@ -48,29 +48,27 @@ def __init__(
48
48
"""
49
49
# Running a loop in a background thread allows us to support async
50
50
# methods from non-async environments.
51
- if ToolboxSyncClient .__loop is None :
51
+ if self . __class__ .__loop is None :
52
52
loop = asyncio .new_event_loop ()
53
53
thread = Thread (target = loop .run_forever , daemon = True )
54
54
thread .start ()
55
- ToolboxSyncClient .__thread = thread
56
- ToolboxSyncClient .__loop = loop
55
+ self . __class__ .__thread = thread
56
+ self . __class__ .__loop = loop
57
57
58
58
async def __start_session () -> None :
59
59
# Use a default session if none is provided. This leverages connection
60
60
# pooling for better performance by reusing a single session throughout
61
61
# the application's lifetime.
62
- if ToolboxSyncClient .__session is None :
63
- ToolboxSyncClient .__session = ClientSession ()
64
-
65
- coro = __start_session ()
62
+ if self .__class__ .__session is None :
63
+ self .__class__ .__session = ClientSession ()
66
64
67
65
asyncio .run_coroutine_threadsafe (
68
- __start_session (), ToolboxSyncClient .__loop
66
+ __start_session (), self . __class__ .__loop
69
67
).result ()
70
68
71
- if not ToolboxSyncClient .__session :
69
+ if not self . __class__ .__session :
72
70
raise ValueError ("Session cannot be None." )
73
- self .__async_client = ToolboxClient (url , ToolboxSyncClient .__session )
71
+ self .__async_client = ToolboxClient (url , self . __class__ .__session )
74
72
75
73
def __run_as_sync (self , coro : Awaitable [T ]) -> T :
76
74
"""Run an async coroutine synchronously"""
0 commit comments