77import weakref
88from abc import ABC , abstractmethod
99from collections import OrderedDict
10+ from concurrent .futures import ProcessPoolExecutor
1011from dataclasses import dataclass
1112from pathlib import Path
1213from typing import (
4344 from ..protocol import RobotLanguageServerProtocol
4445 from .namespace import Namespace
4546
46- from .. utils . process_pool import get_process_pool
47+
4748from .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 ()),
0 commit comments