Skip to content

Commit c0517a8

Browse files
committed
use own threadpoolexecutor for run_in_thread
1 parent 9399205 commit c0517a8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

robotcode/language_server/robotframework/diagnostics/namespace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ async def find_variable(
737737
) -> Optional[VariableDefinition]:
738738

739739
await self.ensure_initialized()
740+
740741
if name[:2] == "%{" and name[-1] == "}":
741742
return EnvironmentVariableDefinition(0, 0, 0, 0, "", name, None)
742743

robotcode/utils/async_tools.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,21 @@ async def check_canceled() -> bool:
443443

444444
return True
445445

446+
THREADPOOL_POOL_MAX_WORKERS = None
447+
448+
__tread_pool_executor: Optional[ThreadPoolExecutor] = None
449+
446450

447451
def run_in_thread(func: Callable[..., _T], /, *args: Any, **kwargs: Any) -> asyncio.Future[_T]:
452+
global __tread_pool_executor
448453
loop = asyncio.get_running_loop()
449454
ctx = contextvars.copy_context()
450455
func_call = functools.partial(ctx.run, func, *args, **kwargs)
451-
return cast("asyncio.Future[_T]", loop.run_in_executor(None, cast(Callable[..., _T], func_call)))
456+
457+
if __tread_pool_executor is None:
458+
__tread_pool_executor = ThreadPoolExecutor(THREADPOOL_POOL_MAX_WORKERS)
459+
460+
return cast("asyncio.Future[_T]", loop.run_in_executor(__tread_pool_executor, cast(Callable[..., _T], func_call)))
452461

453462

454463
def run_coroutine_in_thread(

0 commit comments

Comments
 (0)