[PyKDE] Strange thread problems

Michael Zimmermann mz-list at incunabulum.de
Fri Jan 13 08:28:37 GMT 2006


Hi there,

currently I am struggling with some weird thread related issues.
a) Segfaults
b) Application freezes

For an application we fetch a tree structure via network connection. For 
each subtree a separate worker thread  is started. These items fetched 
are communicated to the gui using QCustomEvent subclasses.

a) Segfaults; "QThread object destroyed while running"
The worker threads are generated in the widget responsible for 
displaying the tree structure. Then they are passed to a container / 
controller class that stores threads and does routine managment 
functions (deleting finished threads, queuing). Below is the relevant 
method from the thread container.

def addThread(self, thread, category = defaultCategory):
         self.__createCategory(category)
         threadID = generateUId()
         self.__threads[threadID] = thread
         self.__categories[category].append(threadID)
         self.__threads[threadID].start()
         # FIXME: why sleep needed here?
         time.sleep(0.01)
         return threadID

The problem is as follows: Without the time.sleep(0.01) line the application
- either segfaults (no error message)
- or terminates with the error "QThread object destroyed while running"

Any idea what might cause this?


b) Application freezes

In one of the threads I use a construct as you can see below. Because 
some of the command are quite lengthy I added qApp.processEvents() calls 
to the relevant code sections.

qApp.lock()
ev = ProgressEvent('Loading Groups at Root', step, steps)
QApplication.postEvent(self.__receiver, ev)
ev = RootItemAddedEvent(name, id, obj)
QApplication.postEvent(self.__receiver, ev)
qApp.unlock()
step = step + 1
# qApp.processEvents()

Result: If qApp.processEvents() is called I do get some application 
freezes; wihtout none.

So, did I get the concept of qApp.processEvents() wrong? is such a call 
actually necessary?

Thanks!


-- 
cu,
    Michael

---------------------------
|  mz-list at incunabulum.de |
--------------------------





More information about the PyQt mailing list