From 51d69a28cee7848fc0032907e4a2c1b0f65e753b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 26 May 2012 19:51:27 +0200 Subject: [PATCH] stop imageManager thread on shutdown --- openlp/core/lib/imagemanager.py | 13 +++++----- openlp/core/ui/mainwindow.py | 43 ++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 47a7ed3f6..be870f0d9 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -167,8 +167,9 @@ class ImageManager(QtCore.QObject): self.width = current_screen[u'size'].width() self.height = current_screen[u'size'].height() self._cache = {} - self._imageThread = ImageThread(self) + self.imageThread = ImageThread(self) self._conversion_queue = PriorityQueue() + self.stop_manager = False QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.process_updates) @@ -219,8 +220,8 @@ class ImageManager(QtCore.QObject): Flush the queue to updated any data to update """ # We want only one thread. - if not self._imageThread.isRunning(): - self._imageThread.start() + if not self.imageThread.isRunning(): + self.imageThread.start() def get_image(self, name): """ @@ -282,15 +283,15 @@ class ImageManager(QtCore.QObject): else: log.debug(u'Image in cache %s:%s' % (name, path)) # We want only one thread. - if not self._imageThread.isRunning(): - self._imageThread.start() + if not self.imageThread.isRunning(): + self.imageThread.start() def _process(self): """ Controls the processing called from a ``QtCore.QThread``. """ log.debug(u'_process - started') - while not self._conversion_queue.empty(): + while not self._conversion_queue.empty() and not self.stop_manager: self._process_cache() log.debug(u'_process - ended') diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index bff9203db..5ae97f7f6 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -30,6 +30,7 @@ import os import sys import shutil from tempfile import gettempdir +import time from datetime import datetime from PyQt4 import QtCore, QtGui @@ -1134,6 +1135,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): """ # If we just did a settings import, close without saving changes. if self.settingsImported: + self.cleanUp(False) event.accept() if self.serviceManagerContents.isModified(): ret = self.serviceManagerContents.saveModifiedService() @@ -1156,8 +1158,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): translate('OpenLP.MainWindow', 'Are you sure you want to close OpenLP?'), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Yes | - QtGui.QMessageBox.No), + QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.Yes) if ret == QtGui.QMessageBox.Yes: self.cleanUp() @@ -1168,23 +1169,31 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.cleanUp() event.accept() - def cleanUp(self): + + def cleanUp(self, save_settings=True): """ - Runs all the cleanup code before OpenLP shuts down + Runs all the cleanup code before OpenLP shuts down. + + ``save_settings`` + Switch to prevent saving settings. Defaults to **True**. """ - # Clean temporary files used by services - self.serviceManagerContents.cleanUp() - if QtCore.QSettings().value(u'advanced/save current plugin', - QtCore.QVariant(False)).toBool(): - QtCore.QSettings().setValue(u'advanced/current media plugin', - QtCore.QVariant(self.mediaToolBox.currentIndex())) - # Call the cleanup method to shutdown plugins. - log.info(u'cleanup plugins') - self.pluginManager.finalise_plugins() - # Save settings - self.saveSettings() - # Close down the display - self.liveController.display.close() + self.imageManager.stop_manager = True + while self.imageManager.imageThread.isRunning(): + time.sleep(0.1) + if save_settings: + # Clean temporary files used by services + self.serviceManagerContents.cleanUp() + if QtCore.QSettings().value(u'advanced/save current plugin', + QtCore.QVariant(False)).toBool(): + QtCore.QSettings().setValue(u'advanced/current media plugin', + QtCore.QVariant(self.mediaToolBox.currentIndex())) + # Call the cleanup method to shutdown plugins. + log.info(u'cleanup plugins') + self.pluginManager.finalise_plugins() + # Save settings + self.saveSettings() + # Close down the display + self.liveController.display.close() def serviceChanged(self, reset=False, serviceName=None): """