Skip to content

Commit 8e334aa

Browse files
committed
remove common process_pool
1 parent 3615161 commit 8e334aa

File tree

3 files changed

+77
-126
lines changed

3 files changed

+77
-126
lines changed

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import weakref
88
from abc import ABC, abstractmethod
99
from collections import OrderedDict
10+
from concurrent.futures import ProcessPoolExecutor
1011
from dataclasses import dataclass
1112
from pathlib import Path
1213
from typing import (
@@ -43,7 +44,7 @@
4344
from ..protocol import RobotLanguageServerProtocol
4445
from .namespace import Namespace
4546

46-
from ..utils.process_pool import get_process_pool
47+
4748
from .library_doc import (
4849
ROBOT_LIBRARY_PACKAGE,
4950
ArgumentSpec,
@@ -469,7 +470,7 @@ def __init__(self, parent_protocol: RobotLanguageServerProtocol, folder: Uri, co
469470
self.parent_protocol.documents.did_change.add(self.resource_document_changed)
470471
self._command_line_variables: Optional[List[VariableDefinition]] = None
471472

472-
self.process_pool = get_process_pool()
473+
# self.process_pool = get_process_pool()
473474
self._python_path: Optional[List[str]] = None
474475
self._environment: Optional[Mapping[str, str]] = None
475476

@@ -707,7 +708,8 @@ async def _find_library(self, name: str, base_dir: str, variables: Optional[Dict
707708
if contains_variable(name, "$@&%"):
708709
return await asyncio.wait_for(
709710
asyncio.get_running_loop().run_in_executor(
710-
self.process_pool,
711+
# self.process_pool,
712+
None,
711713
find_library,
712714
name,
713715
str(self.folder.to_path()),
@@ -744,7 +746,8 @@ async def __find_resource(
744746
if contains_variable(name, "$@&%"):
745747
return await asyncio.wait_for(
746748
asyncio.get_running_loop().run_in_executor(
747-
self.process_pool,
749+
# self.process_pool,
750+
None,
748751
find_file,
749752
name,
750753
str(self.folder.to_path()),
@@ -761,16 +764,17 @@ async def __find_resource(
761764
return str(find_file_ex(name, base_dir, self.python_path, file_type))
762765

763766
async def find_variables(self, name: str, base_dir: str, variables: Optional[Dict[str, Any]] = None) -> str:
764-
return await self._variables_files_cache.get(self._find_variables, name, base_dir, variables)
767+
return await self._variables_files_cache.get(self.__find_variables, name, base_dir, variables)
765768

766769
@_logger.call
767-
async def _find_variables(self, name: str, base_dir: str, variables: Optional[Dict[str, Any]] = None) -> str:
770+
async def __find_variables(self, name: str, base_dir: str, variables: Optional[Dict[str, Any]] = None) -> str:
768771
from robot.variables.search import contains_variable
769772

770773
if contains_variable(name, "$@&%"):
771774
return await asyncio.wait_for(
772775
asyncio.get_running_loop().run_in_executor(
773-
self.process_pool,
776+
# self.process_pool,
777+
None,
774778
find_variables,
775779
name,
776780
str(self.folder.to_path()),
@@ -810,26 +814,29 @@ async def get_libdoc_for_library_import(
810814
async def _get_libdoc() -> LibraryDoc:
811815
self._logger.debug(lambda: f"Load Library {source}{repr(args)}")
812816

813-
result = await asyncio.wait_for(
814-
asyncio.get_running_loop().run_in_executor(
815-
self.process_pool,
816-
get_library_doc,
817-
name,
818-
args,
819-
str(self.folder.to_path()),
820-
base_dir,
821-
self.config.python_path if self.config is not None else None,
822-
self.config.env if self.config is not None else None,
823-
self.config.variables if self.config is not None else None,
824-
variables,
825-
),
826-
LOAD_LIBRARY_TIME_OUT,
827-
)
817+
with ProcessPoolExecutor(max_workers=1) as executor:
818+
result = await asyncio.wait_for(
819+
asyncio.get_running_loop().run_in_executor(
820+
executor,
821+
get_library_doc,
822+
name,
823+
args,
824+
str(self.folder.to_path()),
825+
base_dir,
826+
self.config.python_path if self.config is not None else None,
827+
self.config.env if self.config is not None else None,
828+
self.config.variables if self.config is not None else None,
829+
variables,
830+
),
831+
LOAD_LIBRARY_TIME_OUT,
832+
)
828833

829-
if result.stdout:
830-
self._logger.warning(lambda: f"stdout captured at loading library {name}{repr(args)}:\n{result.stdout}")
834+
if result.stdout:
835+
self._logger.warning(
836+
lambda: f"stdout captured at loading library {name}{repr(args)}:\n{result.stdout}"
837+
)
831838

832-
return result
839+
return result
833840

834841
entry_key = _LibrariesEntryKey(source, args)
835842

@@ -989,27 +996,28 @@ async def get_libdoc_for_variables_import(
989996
async def _get_libdoc() -> VariablesDoc:
990997
self._logger.debug(lambda: f"Load variables {source}{repr(args)}")
991998

992-
result = await asyncio.wait_for(
993-
asyncio.get_running_loop().run_in_executor(
994-
self.process_pool,
995-
get_variables_doc,
996-
name,
997-
args,
998-
str(self.folder.to_path()),
999-
base_dir,
1000-
self.config.python_path if self.config is not None else None,
1001-
self.config.env if self.config is not None else None,
1002-
self.config.variables if self.config is not None else None,
1003-
variables,
1004-
),
1005-
LOAD_LIBRARY_TIME_OUT,
1006-
)
1007-
1008-
if result.stdout:
1009-
self._logger.warning(
1010-
lambda: f"stdout captured at loading variables {name}{repr(args)}:\n{result.stdout}"
999+
with ProcessPoolExecutor(max_workers=1) as executor:
1000+
result = await asyncio.wait_for(
1001+
asyncio.get_running_loop().run_in_executor(
1002+
executor,
1003+
get_variables_doc,
1004+
name,
1005+
args,
1006+
str(self.folder.to_path()),
1007+
base_dir,
1008+
self.config.python_path if self.config is not None else None,
1009+
self.config.env if self.config is not None else None,
1010+
self.config.variables if self.config is not None else None,
1011+
variables,
1012+
),
1013+
LOAD_LIBRARY_TIME_OUT,
10111014
)
1012-
return result
1015+
1016+
if result.stdout:
1017+
self._logger.warning(
1018+
lambda: f"stdout captured at loading variables {name}{repr(args)}:\n{result.stdout}"
1019+
)
1020+
return result
10131021

10141022
entry_key = _VariablesEntryKey(source, args)
10151023

@@ -1095,7 +1103,8 @@ async def complete_library_import(
10951103
) -> Optional[List[CompleteResult]]:
10961104
result = await asyncio.wait_for(
10971105
asyncio.get_running_loop().run_in_executor(
1098-
self.process_pool,
1106+
# self.process_pool,
1107+
None,
10991108
complete_library_import,
11001109
name,
11011110
str(self.folder.to_path()),
@@ -1115,7 +1124,8 @@ async def complete_resource_import(
11151124
) -> Optional[List[CompleteResult]]:
11161125
result = await asyncio.wait_for(
11171126
asyncio.get_running_loop().run_in_executor(
1118-
self.process_pool,
1127+
# self.process_pool,
1128+
None,
11191129
complete_resource_import,
11201130
name,
11211131
str(self.folder.to_path()),
@@ -1135,7 +1145,8 @@ async def complete_variables_import(
11351145
) -> Optional[List[CompleteResult]]:
11361146
result = await asyncio.wait_for(
11371147
asyncio.get_running_loop().run_in_executor(
1138-
self.process_pool,
1148+
# self.process_pool,
1149+
None,
11391150
complete_variables_import,
11401151
name,
11411152
str(self.folder.to_path()),
@@ -1155,7 +1166,8 @@ async def resolve_variable(
11551166
) -> Any:
11561167
result = await asyncio.wait_for(
11571168
asyncio.get_running_loop().run_in_executor(
1158-
self.process_pool,
1169+
# self.process_pool,
1170+
None,
11591171
resolve_variable,
11601172
name,
11611173
str(self.folder.to_path()),

robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
cast,
3030
)
3131

32-
from ....utils.path import path_is_relative_to
3332
from ...common.lsp_types import Position, Range
3433
from ..utils.ast_utils import Token, range_from_token
3534
from ..utils.markdownformatter import MarkDownFormatter
@@ -715,15 +714,15 @@ def update_python_path_and_env(
715714
) -> None:
716715
os.chdir(Path(working_dir))
717716

718-
if pythonpath is not None:
719-
for p in pythonpath:
720-
absolute_path = str(Path(p).absolute())
721-
if absolute_path not in sys.path:
722-
sys.path.insert(0, absolute_path)
717+
# if pythonpath is not None:
718+
# for p in pythonpath:
719+
# absolute_path = str(Path(p).absolute())
720+
# if absolute_path not in sys.path:
721+
# sys.path.insert(0, absolute_path)
723722

724-
if environment:
725-
for k, v in environment.items():
726-
os.environ[k] = v
723+
# if environment:
724+
# for k, v in environment.items():
725+
# os.environ[k] = v
727726

728727

729728
__PRELOADED_MODULES: Optional[Set[ModuleType]] = None
@@ -732,18 +731,18 @@ def update_python_path_and_env(
732731
def _update_env(
733732
working_dir: str = ".", pythonpath: Optional[List[str]] = None, environment: Optional[Dict[str, str]] = None
734733
) -> None:
735-
import gc
734+
# import gc
736735

737-
unload_preloaded_modules()
736+
# unload_preloaded_modules()
738737

739-
file = Path(__file__).resolve()
740-
top = file.parents[3]
741-
for p in filter(lambda v: path_is_relative_to(v, top), sys.path.copy()):
742-
sys.path.remove(p)
738+
# file = Path(__file__).resolve()
739+
# top = file.parents[3]
740+
# for p in filter(lambda v: path_is_relative_to(v, top), sys.path.copy()):
741+
# sys.path.remove(p)
743742

744-
importlib.invalidate_caches()
743+
# importlib.invalidate_caches()
745744

746-
gc.collect()
745+
# gc.collect()
747746

748747
update_python_path_and_env(working_dir, pythonpath, environment)
749748

robotcode/language_server/robotframework/utils/process_pool.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)