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

ensure to clean up at startup #28

Merged
merged 1 commit into from
May 31, 2024
Merged
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
8 changes: 5 additions & 3 deletions src/scorep_jupyter/userpersistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def __init__(self, serializer='dill', mode='memory'):
{'os_environ': '', 'sys_path': '', 'var': ''},
'subprocess':
{'os_environ': '', 'sys_path': '', 'var': ''}}
#ensure to start from scratch(e.g. dirs might not be deleted when changing serializer settings at runtime)
self.postprocess(force_clean=True)

def preprocess(self):
uid = str(uuid.uuid4())
Expand Down Expand Up @@ -54,17 +56,17 @@ def preprocess(self):
return False
return True

def postprocess(self):
def postprocess(self, force_clean=False):
"""
Clean up files used for transmitting persistence and running subprocess.
"""
if self.mode == 'memory':
if self.mode == 'memory' or force_clean:
for key1 in self.paths:
for key2 in self.paths[key1]:
fd_path = self.paths[key1][key2]
if os.path.exists(fd_path):
os.unlink(fd_path)
elif self.mode == 'disk':
if self.mode == 'disk' or force_clean:
if os.path.exists(str(self.base_path)):
shutil.rmtree(str(self.base_path))

Expand Down
Loading