[PyQt] Multiprocessing and ProgressBar
Nicola Creati
ncreati at inogs.it
Thu Oct 7 13:13:29 BST 2010
Hello,
I'm trying to develop a simple application that should do some
calculation in a multiprocessing process and update a progress bar. I
have tried to use the signal-slot technology to update the progress bar
but at the end of my computation the gui crashes and i get:
python: ../../src/xcb_io.c:242: process_responses: Assertion `(((long)
(dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
Thi sis the code i'm using:
#--------------------------------------------------------------------------------------------
import sys, time
from multiprocessing import Process
import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui
class Compute(object):
def __init__(self, win):
self.win = win
def calculate(self):
for i in range (100):
self.progressBar(i)
time.sleep(0.05)
def progressBar(self, value):
self.win.updatePb.emit(value)
#-------------------------------------------------------------------------------
class Form(QtGui.QDialog):
updatePb = QtCore.pyqtSignal(int)
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.progressBar = QtGui.QProgressBar()
self.progressBar.setMinimum(0)
self.progressBar.setMaximum(100)
self.progressBar.setValue(0)
bbox = QtGui.QDialogButtonBox()
bbox.setOrientation(QtCore.Qt.Horizontal)
bbox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.progressBar)
layout.addWidget(bbox)
bbox.clicked.connect(self.calculate)
self.updatePb.connect(self.progressBar.setValue)
def calculate(self):
co = Compute(self)
p = Process(target=co.calculate)
p.start()
p.join()
Thanks.
Nicola
More information about the PyQt
mailing list