Skip to content

Commit b1653b8

Browse files
committed
introduce ROBOT_THREADPOOL_POOL_MAX_WORKERS and ROBOT_PROCESS_POOL_MAX_WORKERS environment vars
1 parent 9f40007 commit b1653b8

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

.vscode/launch.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"log.ini",
9393
//"-w",
9494
"--",
95-
//"C:\\tmp\\robottest\\tests\\bdd_style.robot"
95+
//"C:\\tmp\\robottest\\tests\\bdd_style.robot"
9696
]
9797
},
9898
{
@@ -184,6 +184,10 @@
184184
"name": "Run Extension",
185185
"type": "extensionHost",
186186
"request": "launch",
187+
"env": {
188+
"ROBOT_THREADPOOL_POOL_MAX_WORKERS": "6",
189+
"ROBOT_PROCESS_POOL_MAX_WORKERS": "4"
190+
},
187191
"args": [
188192
"--extensionDevelopmentPath=${workspaceFolder}",
189193
],

robotcode/language_server/robotframework/utils/process_pool.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import atexit
4+
import os
45
import signal
56
from concurrent.futures.process import ProcessPoolExecutor
67
from typing import Any, Optional
@@ -30,7 +31,14 @@ def _terminate(*args: Any, **kwargs: Any) -> None:
3031
def get_process_pool() -> ProcessPoolExecutor:
3132
global _process_pool
3233
if _process_pool is None:
33-
_process_pool = ProcessPoolExecutor(max_workers=PROCESS_POOL_MAX_WORKERS, initializer=_init_pool)
34+
_process_pool = ProcessPoolExecutor(
35+
max_workers=(
36+
int(s)
37+
if (s := os.environ.get("ROBOT_PROCESS_POOL_MAX_WORKERS", None)) and s.isnumeric()
38+
else PROCESS_POOL_MAX_WORKERS
39+
),
40+
initializer=_init_pool,
41+
)
3442
atexit.register(_terminate)
3543

3644
try:

robotcode/utils/async_tools.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import contextvars
66
import functools
77
import inspect
8+
import os
89
import threading
910
import weakref
1011
from collections import deque
@@ -443,6 +444,7 @@ async def check_canceled() -> bool:
443444

444445
return True
445446

447+
446448
THREADPOOL_POOL_MAX_WORKERS = None
447449

448450
__tread_pool_executor: Optional[ThreadPoolExecutor] = None
@@ -455,7 +457,13 @@ def run_in_thread(func: Callable[..., _T], /, *args: Any, **kwargs: Any) -> asyn
455457
func_call = functools.partial(ctx.run, func, *args, **kwargs)
456458

457459
if __tread_pool_executor is None:
458-
__tread_pool_executor = ThreadPoolExecutor(THREADPOOL_POOL_MAX_WORKERS)
460+
__tread_pool_executor = ThreadPoolExecutor(
461+
max_workers=(
462+
int(s)
463+
if (s := os.environ.get("ROBOT_THREADPOOL_POOL_MAX_WORKERS", None)) and s.isnumeric()
464+
else THREADPOOL_POOL_MAX_WORKERS
465+
)
466+
)
459467

460468
return cast("asyncio.Future[_T]", loop.run_in_executor(__tread_pool_executor, cast(Callable[..., _T], func_call)))
461469

tests/robotcode/language_server/robotframework/parts/data/.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
},
55
"robotcode.robot.env": {
66
"ENV_VAR": "1"
7-
}
7+
},
8+
"robotcode.languageServer.args": [
9+
"--debugpy"
10+
]
811
}

tests/robotcode/language_server/robotframework/parts/data/lib/alibrary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any
2+
23
from robot.api import logger
34

45

0 commit comments

Comments
 (0)