@@ -53,7 +53,7 @@ def run(self) -> bool:
5353 return self .print_yaml (False , f"Track file { track_file } does not exist. Exiting." )
5454
5555 stop_event = threading .Event ()
56- t = threading .Thread (target = self .writer_thread , args = (self .progress_file , stop_event ))
56+ t = threading .Thread (target = self .writer_thread , args = (self .progress_file , stop_event ), daemon = True )
5757
5858 try :
5959 t .start ()
@@ -72,19 +72,23 @@ def run(self) -> bool:
7272
7373 logger = MyBarLogger (self )
7474
75- audio_clip = AudioFileClip (output_wav )
76- video_clip = ColorClip (size = (720 , 576 ), color = (0 , 0 , 0 ), duration = audio_clip .duration )
77- video_clip = video_clip .with_audio (audio_clip )
78- video_clip .write_videofile (output_mp4 , fps = 24 , logger = logger )
75+ with AudioFileClip (output_wav ) as audio_clip :
76+ with ColorClip (size = (720 , 576 ), color = (0 , 0 , 0 ), duration = audio_clip .duration ) as video_clip :
77+ video_clip = video_clip .with_audio (audio_clip )
78+ video_clip .write_videofile (output_mp4 , fps = 24 , logger = logger )
7979
8080 return self .print_yaml (True , "" )
8181 except Exception as e :
8282 print (f"Error creating wav or mp4 file: { str (e )} " , file = sys .stderr )
8383 return self .print_yaml (False , f"Error creating wav or mp4 file { str (e )} " )
8484 finally :
8585 stop_event .set ()
86- t .join ()
87-
86+ t .join (timeout = 2 )
87+ try :
88+ audio_clip .close ()
89+ video_clip .close ()
90+ except Exception :
91+ pass
8892
8993 def print_yaml (self , successful : bool , error : str ) -> bool :
9094 data = dict (
@@ -102,11 +106,14 @@ def print_yaml(self, successful: bool, error: str) -> bool:
102106
103107 def writer_thread (self , filename , stop_event ):
104108 while not stop_event .is_set ():
105- with open (filename , "w" ) as f :
106- print (f"writer thread { self .phase } { self .phase_progress } /100" )
107- f .write (f"{ self .phase } |{ self .phase_progress } \n " )
108- f .flush () # ensure immediate write
109- time .sleep (0.5 ) # 500 ms
109+ try :
110+ with open (filename , "w" ) as f :
111+ print (f"writer thread { self .phase } { self .phase_progress } /100" )
112+ f .write (f"{ self .phase } |{ self .phase_progress } \n " )
113+ f .flush () # ensure immediate write
114+ except Exception :
115+ pass
116+ time .sleep (0.5 ) # 500 ms
110117
111118
112119class MyBarLogger (ProgressBarLogger ):
0 commit comments