12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+
15
16
import asyncio
16
17
from threading import Thread
17
18
from typing import Any , Callable , Coroutine , Mapping , Optional , TypeVar , Union
@@ -59,7 +60,7 @@ async def create_client():
59
60
60
61
# Ignoring type since we're already checking the existence of a loop above.
61
62
self .__async_client = asyncio .run_coroutine_threadsafe (
62
- create_client (), self .__class__ .__loop # type: ignore
63
+ create_client (), self .__class__ .__loop
63
64
).result ()
64
65
65
66
def close (self ):
@@ -101,11 +102,10 @@ def load_tool(
101
102
"""
102
103
coro = self .__async_client .load_tool (name , auth_token_getters , bound_params )
103
104
104
- # We have already created a new loop in the init method in case it does not already exist
105
- async_tool = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result () # type: ignore
106
-
107
105
if not self .__loop or not self .__thread :
108
106
raise ValueError ("Background loop or thread cannot be None." )
107
+
108
+ async_tool = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result ()
109
109
return ToolboxSyncTool (async_tool , self .__loop , self .__thread )
110
110
111
111
def load_toolset (
@@ -130,11 +130,10 @@ def load_toolset(
130
130
"""
131
131
coro = self .__async_client .load_toolset (name , auth_token_getters , bound_params )
132
132
133
- # We have already created a new loop in the init method in case it does not already exist
134
- async_tools = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result () # type: ignore
135
-
136
133
if not self .__loop or not self .__thread :
137
134
raise ValueError ("Background loop or thread cannot be None." )
135
+
136
+ async_tools = asyncio .run_coroutine_threadsafe (coro , self .__loop ).result () # type: ignore
138
137
return [
139
138
ToolboxSyncTool (async_tool , self .__loop , self .__thread )
140
139
for async_tool in async_tools
0 commit comments