Skip to content

Commit

Permalink
fixed temp file deletio
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilJohan committed Jul 24, 2024
1 parent b2cba49 commit b6210c4
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Smelt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
2. Use the GUI to select files and start processing.
"""
import atexit
import glob
import platform
import queue
Expand All @@ -25,6 +26,7 @@
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
subprocesses = []


def get_ffmpeg_path():
Expand Down Expand Up @@ -486,7 +488,7 @@ def recognize_and_combine_audio_files(self, selected_audio_file):
proceed_combine = self.exist_check(combined_audio_file)

ffmpeg_combine_audio_cmd = [
'ffmpeg',
ffmpeg_path,
'-i', matching_files['L'],
'-i', matching_files['R'],
'-i', matching_files['C'],
Expand Down Expand Up @@ -1014,6 +1016,7 @@ def run_ffmpeg_command(self, command):
Returns:
bool: True if the command was successful, False otherwise.
"""
global subprocesses
if platform.system() == 'Windows':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
Expand All @@ -1022,6 +1025,7 @@ def run_ffmpeg_command(self, command):

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
startupinfo=startupinfo, universal_newlines=True)
subprocesses.append(process)
stdout_queue = queue.Queue()
stderr_queue = queue.Queue()

Expand Down Expand Up @@ -1085,10 +1089,31 @@ def enqueue_output(pipe, queue):
return True


def cleanup():
# Terminate all subprocesses
global subprocesses
for process in subprocesses:
if process.poll() is None: # If process is still running
process.terminate() # Gracefully terminate the process
try:
process.wait(timeout=5) # Wait for process to terminate
except subprocess.TimeoutExpired:
process.kill() # Forcefully kill the process if it doesn't terminate

# Perform any other necessary cleanup here
# For example, closing open files, releasing resources, etc.


atexit.register(cleanup)
app = QApplication(sys.argv)
app.setStyle('Breeze')

window = Smelt()
window.show()

def on_exit():
cleanup()
sys.exit()

app.aboutToQuit.connect(on_exit)
sys.exit(app.exec_())

0 comments on commit b6210c4

Please sign in to comment.