Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Wrong shelf loading #1578

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions asyncua/server/address_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,25 +711,23 @@ def make_aspace_shelf(self, path: Path):
for nodeid, ndata in self._nodes.items():
s[nodeid.to_string()] = ndata

def load_aspace_shelf(self, path):
def load_aspace_shelf(self, path: Path):
"""
Load the standard address space nodes from a python shelve via LazyLoadingDict as needed.
The dump() method can no longer be used if the address space is being loaded from a shelf

Note: Intended for slow devices, such as Raspberry Pi, to greatly improve start up time
"""
raise NotImplementedError

# ToDo: async friendly implementation - load all at once?
class LazyLoadingDict(collections.abc.MutableMapping):
"""
Special dict that only loads nodes as they are accessed. If a node is accessed it gets copied from the
shelve to the cache dict. All user nodes are saved in the cache ONLY. Saving data back to the shelf
shelf to the cache dict. All user nodes are saved in the cache ONLY. Saving data back to the shelf
is currently NOT supported
"""

def __init__(self, source):
self.source = source # python shelf
def __init__(self, source: shelve.Shelf):
self.source: shelve.Shelf = source # python shelf
self.cache = {} # internal dict

def __getitem__(self, key):
Expand Down Expand Up @@ -759,7 +757,7 @@ def __len__(self):
# only returns the length of items in the cache, not unaccessed items in the shelf
return len(self.cache)

self._nodes = LazyLoadingDict(shelve.open(path, "r"))
self._nodes = LazyLoadingDict(shelve.open(str(path), "r"))

def read_attribute_value(self, nodeid: ua.NodeId, attr: ua.AttributeIds) -> ua.DataValue:
# self.logger.debug("get attr val: %s %s", nodeid, attr)
Expand Down
1 change: 0 additions & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ async def test_message_limits_works(restore_transport_limits_server: Server):
await n.read_value()


@pytest.mark.xfail(reason="FIXME broken", strict=True)
async def test_runTest(tmp_path: Path):
demo_shelf_file: Path = tmp_path / "some_shelf"

Expand Down
Loading