Skip to content

Commit c36683e

Browse files
committed
test: use Lock instead of RLock for AsyncLRUCache
1 parent 1224dae commit c36683e

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,32 +1026,30 @@ async def _get_libdoc(name: str, args: Tuple[Any, ...], working_dir: str, base_d
10261026
LOAD_LIBRARY_TIME_OUT,
10271027
)
10281028

1029-
if result.stdout:
1030-
self._logger.warning(
1031-
lambda: f"stdout captured at loading library {name}{repr(args)}:\n{result.stdout}"
1032-
)
1033-
try:
1034-
if meta is not None:
1035-
meta_file = Path(self.lib_doc_cache_path, meta.filepath_base.with_suffix(".meta.json"))
1036-
spec_file = Path(self.lib_doc_cache_path, meta.filepath_base.with_suffix(".spec.json"))
1037-
spec_file.parent.mkdir(parents=True, exist_ok=True)
1029+
if result.stdout:
1030+
self._logger.warning(lambda: f"stdout captured at loading library {name}{repr(args)}:\n{result.stdout}")
1031+
try:
1032+
if meta is not None:
1033+
meta_file = Path(self.lib_doc_cache_path, meta.filepath_base.with_suffix(".meta.json"))
1034+
spec_file = Path(self.lib_doc_cache_path, meta.filepath_base.with_suffix(".spec.json"))
1035+
spec_file.parent.mkdir(parents=True, exist_ok=True)
10381036

1039-
try:
1040-
spec_file.write_text(as_json(result), "utf-8")
1041-
except (SystemExit, KeyboardInterrupt):
1042-
raise
1043-
except BaseException as e:
1044-
raise RuntimeError(f"Cannot write spec file for library '{name}' to '{spec_file}'") from e
1037+
try:
1038+
spec_file.write_text(as_json(result), "utf-8")
1039+
except (SystemExit, KeyboardInterrupt):
1040+
raise
1041+
except BaseException as e:
1042+
raise RuntimeError(f"Cannot write spec file for library '{name}' to '{spec_file}'") from e
10451043

1046-
meta_file.write_text(as_json(meta), "utf-8")
1047-
else:
1048-
self._logger.debug(lambda: f"Skip caching library {name}{repr(args)}")
1049-
except (SystemExit, KeyboardInterrupt):
1050-
raise
1051-
except BaseException as e:
1052-
self._logger.exception(e)
1044+
meta_file.write_text(as_json(meta), "utf-8")
1045+
else:
1046+
self._logger.debug(lambda: f"Skip caching library {name}{repr(args)}")
1047+
except (SystemExit, KeyboardInterrupt):
1048+
raise
1049+
except BaseException as e:
1050+
self._logger.exception(e)
10531051

1054-
return result
1052+
return result
10551053

10561054
resolved_args = resolve_args(
10571055
args,

robotcode/utils/async_cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import defaultdict
22
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, TypeVar, cast
33

4-
from .async_tools import RLock
4+
from .async_tools import Lock
55

66
_T = TypeVar("_T")
77

@@ -16,7 +16,7 @@ class CacheEntry:
1616
def __init__(self) -> None:
1717
self.data: Any = None
1818
self.has_data: bool = False
19-
self.lock = RLock()
19+
self.lock = Lock()
2020

2121

2222
class AsyncSimpleLRUCache:
@@ -27,7 +27,7 @@ def __init__(self, max_items: Optional[int] = 128) -> None:
2727
self._order: Optional[List[Tuple[Any, ...]]] = None
2828
if self.max_items:
2929
self._order = []
30-
self._lock = RLock()
30+
self._lock = Lock()
3131

3232
async def has(self, *args: Any, **kwargs: Any) -> bool:
3333
key = self._make_key(*args, **kwargs)

0 commit comments

Comments
 (0)