Skip to content

Commit

Permalink
Properly terminate Progress Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Mar 8, 2021
1 parent e5ea475 commit db9b559
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 5 additions & 2 deletions NotEnoughAV1Encodes-Qt/NotEnoughAV1Encodes-Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,14 @@ def get_source_framecount(self):

def calc_progress(self):
log_path = os.path.join(self.tempDir, self.temp_dir_file_name, "Progress")
mux_path = os.path.join(self.tempDir, self.temp_dir_file_name, "Chunks", "mux.txt")
# Create a QThread object
self.calc_thread = QThread()
# Create a worker object
self.calc_worker = worker_progress.WorkerProgress()
# Move worker to the thread
self.calc_worker.moveToThread(self.calc_thread)
# Connect signals and slots
self.calc_thread.started.connect(partial(self.calc_worker.run, log_path, mux_path))
self.calc_thread.started.connect(partial(self.calc_worker.run, log_path))
self.calc_worker.finished.connect(self.calc_thread.quit)
self.calc_worker.finished.connect(self.calc_worker.deleteLater)
self.calc_thread.finished.connect(self.calc_thread.deleteLater)
Expand Down Expand Up @@ -1164,6 +1163,10 @@ def main_encode(self):
self.calc_progress()

def worker_finished(self):
# Stops Progress Worker
self.calc_worker.stop()
self.calc_thread.quit()
self.calc_thread.wait()
self.labelStatus.setText("Status: Muxing")
self.main_muxing()
self.labelStatus.setText("Status: Finished")
Expand Down
19 changes: 12 additions & 7 deletions NotEnoughAV1Encodes-Qt/worker_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ class WorkerProgress(QObject):
"""
progress = pyqtSignal(int)
finished = pyqtSignal()
_is_running = True
@pyqtSlot()
def run(self, progress_path, mux_path):
def run(self, progress_path):
"""
Attributes
----------
progress_path : path to where the log files are located
"""
mux_file_not_written = True
while mux_file_not_written:
while self._is_running:
# Pulls the framecount every 2 seconds
time.sleep(2)
total_encoded_frames = 0
try:
for filename in os.listdir(progress_path):
Expand All @@ -41,7 +40,13 @@ def run(self, progress_path, mux_path):
total_encoded_frames += int(lines[idx[-1]][6:])
except:
pass
if os.path.isfile(mux_path):
mux_file_not_written = False
self.progress.emit(total_encoded_frames)
if self._is_running:
self.progress.emit(total_encoded_frames)
time.sleep(2)
self.finished.emit()

def stop(self):
"""
Stops the while loop in run()
"""
self._is_running = False

0 comments on commit db9b559

Please sign in to comment.