Skip to content
Snippets Groups Projects

Clean up waveform thread when program exits

Merged Kien Le requested to merge bug-#42-waveform_plot_quits_ungracefully_on_program_exit into master
1 file
+ 15
4
Compare changes
  • Side-by-side
  • Inline
@@ -31,7 +31,6 @@ from sohstationviewer.view.plotting.waveform_dialog import WaveformDialog
from sohstationviewer.view.search_message.search_message_dialog import (
SearchMessageDialog
)
from sohstationviewer.view.plotting.state_of_health_widget import SOHWidget
from sohstationviewer.view.help_view import HelpBrowser
from sohstationviewer.view.ui.main_ui import UIMainWindow
from sohstationviewer.view.util.enums import LogType
@@ -142,7 +141,7 @@ class MainWindow(QtWidgets.QMainWindow, UIMainWindow):
"""
waveform_dlg: widget to display waveform channels' plotting
"""
self.waveform_dlg: SOHWidget = WaveformDialog(self)
self.waveform_dlg: WaveformDialog = WaveformDialog(self)
"""
tps_dlg: dialog to display time-power-squared of waveform channels
"""
@@ -854,8 +853,7 @@ class MainWindow(QtWidgets.QMainWindow, UIMainWindow):
def closeEvent(self, event: QtGui.QCloseEvent) -> None:
"""
Cleans up when the user exits the program. Currently only clean up
running data loaders.
Cleans up when the user exits the program.
:param event: parameter of method being overridden
"""
@@ -867,6 +865,19 @@ class MainWindow(QtWidgets.QMainWindow, UIMainWindow):
self.data_loader.thread.quit()
self.data_loader.thread.wait()
# If we don't explicitly clean up the running processing threads,
# there is a high chance that they will attempt to access temporary
# files that have already been cleaned up. While this should not be a
# problem, it is still a bad idea to touch the file system when you are
# not supposed to.
if self.is_plotting_waveform:
self.waveform_dlg.plotting_widget.request_stop()
self.waveform_dlg.plotting_widget.thread_pool.waitForDone()
if self.is_plotting_tps:
self.tps_dlg.plotting_widget.request_stop()
self.tps_dlg.plotting_widget.thread_pool.waitForDone()
# close all remaining windows
for window in QtWidgets.QApplication.topLevelWidgets():
window.close()
Loading