backups: deal with multithread restore process

Only GUI thread can interact with GUI widgets, so queue the requests and
process from GUI thread. This applies to backup progress reports.
This commit is contained in:
Marek Marczykowski-Górecki 2013-11-29 03:26:51 +01:00
parent 9c2db2f87c
commit 668bb1fdf6

View File

@ -47,8 +47,8 @@ from ui_restoredlg import *
from multiselectwidget import * from multiselectwidget import *
from backup_utils import * from backup_utils import *
from multiprocessing import Queue
from multiprocessing.queues import Empty
class RestoreVMsWindow(Ui_Restore, QWizard): class RestoreVMsWindow(Ui_Restore, QWizard):
@ -66,6 +66,7 @@ class RestoreVMsWindow(Ui_Restore, QWizard):
self.restore_options = None self.restore_options = None
self.backup_vms_list = None self.backup_vms_list = None
self.func_output = [] self.func_output = []
self.feedback_queue = Queue()
self.excluded = {} self.excluded = {}
@ -166,13 +167,14 @@ class RestoreVMsWindow(Ui_Restore, QWizard):
self.func_output.append(s) self.func_output.append(s)
def restore_error_output(self, s): def restore_error_output(self, s):
self.emit(SIGNAL("restore_progress(QString)"), '<font color="red">{0}</font>'.format(s)) self.feedback_queue.put((SIGNAL("restore_progress(QString)"), '<font color="red">{0}</font>'.format(s)))
def restore_output(self, s): def restore_output(self, s):
self.emit(SIGNAL("restore_progress(QString)"),'<font color="black">{0}</font>'.format(s)) self.feedback_queue.put((SIGNAL("restore_progress(QString)"),'<font color="black">{0}</font>'.format(s)))
def update_progress_bar(self, value): def update_progress_bar(self, value):
self.emit(SIGNAL("backup_progress(int)"), value) print "progress %d" % value
self.feedback_queue.put((SIGNAL("backup_progress(int)"), value))
def __do_restore__(self, thread_monitor): def __do_restore__(self, thread_monitor):
err_msg = [] err_msg = []
@ -237,12 +239,18 @@ class RestoreVMsWindow(Ui_Restore, QWizard):
while not self.thread_monitor.is_finished(): while not self.thread_monitor.is_finished():
self.app.processEvents() self.app.processEvents()
time.sleep (0.1) time.sleep (0.1)
try:
for (signal,data) in iter(self.feedback_queue.get_nowait,None):
self.emit(signal,data)
except Empty:
pass
#if not self.thread_monitor.success: #if not self.thread_monitor.success:
#QMessageBox.warning (None, "Backup error!", "ERROR: {1}".format(self.vm.name, self.thread_monitor.error_msg)) #QMessageBox.warning (None, "Backup error!", "ERROR: {1}".format(self.vm.name, self.thread_monitor.error_msg))
if self.dev_mount_path != None: if self.dev_mount_path != None:
umount_device(self.dev_mount_path) umount_device(self.dev_mount_path)
self.progress_bar.setValue(100)
self.button(self.FinishButton).setEnabled(True) self.button(self.FinishButton).setEnabled(True)
def all_vms_good(self): def all_vms_good(self):