Skip to content

Commit

Permalink
Clean up frames whether error occured or not upon __exit__
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ramadhan committed Jun 29, 2024
1 parent 5eb973c commit 431ff58
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions matplotloom/loom.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None:
self.save_video()
else:
try:
if exc_type is None:
self.save_video()
else:
if self.verbose:
print(f"An error occurred: {exc_type.__name__}: {exc_value}")
print("Animation was not saved.")
finally:
if not self.keep_frames:
for frame_filepath in self.frame_filepaths:
if frame_filepath.exists():
frame_filepath.unlink()

if self.verbose:
print(f"An error occurred: {exc_type.__name__}: {exc_value}")
print("Animation was not saved.")


return False # Propagate the exception if there was one

def save_frame(self, fig, frame_number=None):
Expand Down

0 comments on commit 431ff58

Please sign in to comment.