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

Prevent errors caused by unregistering memory twice. #27

Merged
merged 1 commit into from
Jan 29, 2025
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
10 changes: 9 additions & 1 deletion pshmem/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ def __init__(self):
self.reg = dict()

def register(self, name, buffer, noderank):
if name in self.reg:
msg = f"Buffer {name} already registered on node rank {noderank}"
raise RuntimeError(msg)
self.reg[name] = (buffer, noderank)

def unregister(self, name):
del self.reg[name]
if name in self.reg:
buf, noderank = self.reg[name]
buf.close()
if noderank == 0:
buf.unlink()
del self.reg[name]

def cleanup(self):
for name, (buf, noderank) in self.reg.items():
Expand Down
6 changes: 1 addition & 5 deletions pshmem/shmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,8 @@ def close(self):
del self._flat
if hasattr(self, "_shmem"):
if self._shmem is not None:
# Unregister the shared memory buffer, since we are about to close it.
# Unregister the shared memory buffer and close it.
registry.unregister(self._name)
self._shmem.close()
if self._noderank == 0:
self._shmem.unlink()
del self._shmem
self._shmem = None
self._flat = None
self.data = None
Expand Down