From f741217c34f307ee45752cc13dbccc0c030f1eb9 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Wed, 11 May 2022 12:48:08 -0700 Subject: [PATCH] Make sure keyboard interrupted renders don't overwrite pre-existing video files --- manimlib/scene/scene.py | 2 +- manimlib/scene/scene_file_writer.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index b189f606..7b29deae 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -124,6 +124,7 @@ class Scene(object): except KeyboardInterrupt: # Get rid keyboard interupt symbols print("", end="\r") + self.file_writer.ended_with_interrupt = True self.tear_down() def setup(self) -> None: @@ -190,7 +191,6 @@ class Scene(object): # As long as the copied selection starts with a comment, # this will revert to the state of the scene at the first # point of running. - def checkpoint_paste(skip=False, show_progress=False): def checkpoint_paste(skip=False, show_progress=True): pasted = pyperclip.paste() line0 = pasted.lstrip().split("\n")[0] diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index fffbd788..d2e211eb 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -54,6 +54,7 @@ class SceneFileWriter(object): self.scene: Scene = scene self.writing_process: sp.Popen | None = None self.has_progress_display: bool = False + self.ended_with_interrupt: bool = False self.init_output_directories() self.init_audio() @@ -297,7 +298,11 @@ class SceneFileWriter(object): self.writing_process.terminate() if self.has_progress_display: self.progress_display.close() - shutil.move(self.temp_file_path, self.final_file_path) + + if not self.ended_with_interrupt: + shutil.move(self.temp_file_path, self.final_file_path) + else: + self.movie_file_path = self.temp_file_path def combine_movie_files(self) -> None: kwargs = {