Hello,
I have attached a short script that I think demonstrates a bug in the PyQt4
snapshots. I expect the following output on the command line:
0
1
[...]
9998
9999
complete
The script runs as expected with PyQt4-4.4.4 on 64bit Kubuntu Jaunty
(although I have to invoke ctrl-z to exit the script. I don't know how to
improve that part, but that is not the subject of this post.)
With the most recent (20090507) snapshots installed on 64bit Gentoo, the
script does not run to completion. The script usually hangs up before
anything is printed at the command line, although occasionally the thread
gets part way through the loop before it hangs up.
Darren
from __future__ import with_statement
import copy
import sys
from PyQt4 import QtGui, QtCore
class MyData(object):
def _get_value(self):
with self._lock:
return copy.copy(self._value)
def _set_value(self, value):
with self._lock:
self._value = copy.copy(value)
value = property(_get_value, _set_value)
def __init__(self):
self._lock = QRLock()
self._value = []
def append(self, value):
with self._lock:
self._value.append(value)
class QRLock(QtCore.QMutex):
"""
"""
def __init__(self):
QtCore.QMutex.__init__(self, QtCore.QMutex.Recursive)
def __enter__(self):
self.lock()
return self
def __exit__(self, type, value, traceback):
self.unlock()
class MyThread(QtCore.QThread):
@property
def stopped(self):
with self._lock:
return self._stopped
def __init__(self, data):
QtCore.QThread.__init__(self)
self._lock = QRLock()
self._data = data
self._stopped = False
def run(self):
for i in xrange(10000):
if self.stopped:
break
self._data.append(i)
self.emit(QtCore.SIGNAL('newData'), i)
self.emit(QtCore.SIGNAL('processComplete'), i)
def stop(self):
with self._lock:
self._stopped = True
class ProcessData(QtCore.QObject):
def __init__(self):
QtCore.QObject.__init__(self)
self._myData = MyData()
self._thread = MyThread(self._myData)
self.connect(self._thread, QtCore.SIGNAL('newData'), self.report)
self.connect(self._thread, QtCore.SIGNAL('processComplete'), self.cleanup)
self._thread.start()
def cleanup(self):
self._thread = None
print 'complete'
def report(self, i):
print self._myData.value[i]
app = QtCore.QCoreApplication(sys.argv)
test = ProcessData()
sys.exit(app.exec_())
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt