On Mon, Aug 16, 2004 at 04:10:50PM +0100, Phil Thompson wrote:
> On Friday 06 August 2004 3:22 pm, Truls A. Tangstad wrote:
> > It seems that the destructor of QCustomEvent causes problems/hangs
> > just by creating an instance of it and then deleting it in a thread
> > other than the GUI/event/main-thread. This only occurs in version 3.12
> > of PyQt, and was not a problem in 3.11.
> >
> > The problem does not seem to occur when sending the event object to
> > qt.qApp.postEvent before deleting it, even when the posting function
> > should be the only one left with a reference to the object.
> >
> > One rarely creates a QCustomEvent without posting it, but the behavior
> > is still strange.
> >
> > In the enclosed example two threads are started, one creates a
> > QCustomEvent object, posts it, then deletes it, after waiting to make
> > sure the event handler is done with it. The second thread creates a
> > QCustomEvent object then deletes it, causing the application to hang
> > with PyQt 3.12.
> >
> > I'm running on Debian Unstable using the following package versions:
> > libqt3c102-mt 3.2.3-4
> > python2.3-qt3 3.12-1
> > python2.3-sip4-qt3 4.0-2
> >
> > [1] http://mats.imk.fraunhofer.de/pipermail/pykde/2004-August/008303.html
> Please read the PyQt documentation regarding using the Python thread module
> with PyQt - you aren't following the guidelines.
>
> Attached is a version of your script which uses QThread instead and seems to
> work fine.
I've been modifying our program to use QThreads, but deadlocks (hangs)
still occur. Some of the problems can be related to the following
problem which I've been able to distill in the attached script, which
is a modified version of the one you posted.
When the event thread is busy in QCustomEvents destructor, posting new
events, even from QThreads, hangs the entire application. I'm not sure
if this is specific to QCustomEvents destructor or that postEvent has
greater issues though.
I'm currently running Debian Unstable using the following package versions:
libqt3c102-mt 3.3.3-3
python2.3-qt3 3.12-2
python2.3-sip4-qt3 4.0.1-1
--
Truls A. Tangstad - <[EMAIL PROTECTED] e r o c a m p.org>
import qt
import time
def trig():
PostSlow.start()
PostAgain.start()
class SlowDeletingEvent(qt.QCustomEvent):
def __del__(self):
print "deleting first event"
time.sleep(2)
print "deleted"
class PostSlow(qt.QThread):
def run(self):
print "PostSlow"
qEvent = SlowDeletingEvent(1234)
print "posting first event"
qt.qApp.postEvent(qt.qApp, qEvent)
print "posted"
class PostAgain(qt.QThread):
def run(self):
# let PostSlow finish
time.sleep(0.5)
print "PostAgain"
qEvent = qt.QCustomEvent(1234)
print "posting new event while gui thread is still deleting first (hangs here)"
qt.qApp.postEvent(qt.qApp, qEvent)
print "posted"
qApp = qt.QApplication([])
PostSlow = PostSlow()
PostAgain = PostAgain()
# make sure code isn't run until event thread has started
qt.QTimer.singleShot(0, trig)
# exit application when done
qt.QTimer.singleShot(2500, qt.qApp.exit)
qApp.exec_loop()
print "No problems if you've come this far"
_______________________________________________
PyKDE mailing list [EMAIL PROTECTED]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde