Skip to content
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: 6 additions & 4 deletions distarray/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

from distarray.ipython_utils import IPythonClient

def cleanup(view, module_name, context_name):
def cleanup(view, module_name, prefix):
""" Delete Context object with the given name from the given module"""
def _cleanup(module_name, context_name):
def _cleanup(module_name, prefix):
ns = __import__(module_name)
delattr(ns, context_name)
for name in vars(ns).copy():
if name.startswith(prefix):
delattr(ns, name)

view.apply_async(_cleanup, module_name, context_name)
view.apply_sync(_cleanup, module_name, prefix)


def cleanup_all(module_name, prefix):
Expand Down
2 changes: 1 addition & 1 deletion distarray/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def delete_key(self, key):

def cleanup(self):
""" Delete keys that this context created from all the engines. """
cleanup.cleanup(view=self.view, module_name='__main__', context_name=self.context_key)
cleanup.cleanup(view=self.view, module_name='__main__', prefix=self.context_key)

def close(self):
self.cleanup()
Expand Down