Re: [PyQt] Crash (segfault) when using PyQt4 Qthread

2008-11-17 Thread chris3110

Hi David,

thanks a lot for your answer.  In fact this little program is my very first
attempt at a GUI application in Python, so it may very well look quite weird
to you :-)  Basically what I'm trying to do is very simple, I have a main
window that's waiting for input.  When you drag or paste a URL into it and
click "Ok", a separate thread is spawned and starts crawling the URL.  What
I want is the debug ouptut of this thread to go to a text box in the main
window.  Eventually there would be several worker threads, each with its own
output box in a tabbed interface for instance.

So this hopefully clarifies the intent of the piece of code I've submitted. 
I fully expect the naive approach I considered to be flawed, and I'd be more
than happy if somebody could quickly sketch the correct architecture for
this type of problems.

However besides that I still think that whatever garbage I feed it with,
Python should not give me a bare segfault.  This is expected in low-level
languages like C/C++ and perhaps Java but my understanding was that higher
level languages like Perl and Python were precisely aiming at providing an
abstraction layer on top of the operating system that would make this kind
of situation impossible.

Besides, the fact that nobody's seemingly able to reproduce the crash is
very annoying.  Isn't there a way to at least determine which library is
crashing, or even getting a stacktrace or something ?

Thanks for your help,
Christian



David Boddie wrote:
> 
> Looking at your code, I'm concerned that you're accessing various logging
> objects from two threads without any obvious safeguards.
> 
> In your main widget class, you do this:
> 
> self.log = logging.getLogger('u.crawler')
> self.log.addHandler(WindowLogger(self.winlog))
> 
> So, all these objects are being created in the main GUI thread. Then you
> create a thread, passing in a Page object:
> 
> def accept(self):
> thread = CrawlerThread(Page())
> UrlCrawler.threadList.append(thread)
> thread.start()
> 
> The page object also gets a reference to the logging object:
> 
> class Page:
> def __init__(self):
> self.log = logging.getLogger('u.crawler')
> 
> In the thread, you access this object via the page object:
> 
> def run(self):
> page = self.page
> page.log.info('Starting')
> page.analyze()
> 
> It seems that you have various objects that are being created in one
> thread
> and used in another. Maybe that's OK if the main thread isn't trying to
> access them at the same time as the worker thread.
> 
> One other point is that the logging handler you supply to the logging
> objects
> accesses a GUI component:
> 
> class WindowLogger(logging.Handler):
> def __init__(self, window):
> self.window = window
> logging.Handler.__init__(self)
> 
> def emit(self, record):
> self.window.appendPlainText(record.getMessage())
> 
> Since I presume this is being called from the worker thread, I would
> suspect
> that this could be the source of your problems. Maybe you should emit a
> signal here that you can receive in a slot in your UrlCrawler class.
> 
> I hope this helps. I'm sure that other people can correct me if I've
> misidentified the cause of the problem.
> 
> David
> ___
> 

-- 
View this message in context: 
http://www.nabble.com/Crash-%28segfault%29-when-using-PyQt4-Qthread-tp20255394p20550338.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Crash (segfault) when using PyQt4 Qthread

2008-11-14 Thread David Boddie
On Sat Nov 15 00:23:53 GMT 2008, chris3110 wrote:

> Also are you positive you can't reproduce this pb, even when clicking a lot
> in and out of the window, coming back and forth to it, etc ?  I find it
> hard to believe that this could be related to the python version.

I also tried to run it with Python 2.5.2, PyQt 4.4.3 and Qt 4.4.3 on
Ubuntu and couldn't make it crash.

Looking at your code, I'm concerned that you're accessing various logging
objects from two threads without any obvious safeguards.

In your main widget class, you do this:

self.log = logging.getLogger('u.crawler')
self.log.addHandler(WindowLogger(self.winlog))

So, all these objects are being created in the main GUI thread. Then you
create a thread, passing in a Page object:

def accept(self):
thread = CrawlerThread(Page())
UrlCrawler.threadList.append(thread)
thread.start()

The page object also gets a reference to the logging object:

class Page:
def __init__(self):
self.log = logging.getLogger('u.crawler')

In the thread, you access this object via the page object:

def run(self):
page = self.page
page.log.info('Starting')
page.analyze()

It seems that you have various objects that are being created in one thread
and used in another. Maybe that's OK if the main thread isn't trying to
access them at the same time as the worker thread.

One other point is that the logging handler you supply to the logging objects
accesses a GUI component:

class WindowLogger(logging.Handler):
def __init__(self, window):
self.window = window
logging.Handler.__init__(self)

def emit(self, record):
self.window.appendPlainText(record.getMessage())

Since I presume this is being called from the worker thread, I would suspect
that this could be the source of your problems. Maybe you should emit a
signal here that you can receive in a slot in your UrlCrawler class.

I hope this helps. I'm sure that other people can correct me if I've
misidentified the cause of the problem.

David
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Crash (segfault) when using PyQt4 Qthread

2008-11-14 Thread chris3110


Ok, can you possibly indicate me where to start ?  I'm not too knowledgeable
about C++.

Also are you positive you can't reproduce this pb, even when clicking a lot
in and out of the window, coming back and forth to it, etc ?  I find it hard
to believe that this could be related to the python version.

Thanks,
Chris


Phil Thompson-5 wrote:
> 
> On Thu, 13 Nov 2008 16:58:01 -0800 (PST), chris3110
> <[EMAIL PROTECTED]> wrote:
>> Hi Phil, 
>> 
>> I've compiled the following snapshots 
>> 
>> PyQt-x11-gpl-4.4.4-snapshot-20081101 
>> sip-4.7.8-snapshot-20081102 
>> 
>> and I still have a segfault.  I'm still using python 2.5 though. 
>> 
>> Is there a way to trace the source of the pb somehow ? 
> 
> I think you'd need to debug it at the C++ level.
> 
> Phil
> ___
> PyQt mailing listPyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Crash-%28segfault%29-when-using-PyQt4-Qthread-tp20255394p20510757.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Crash (segfault) when using PyQt4 Qthread

2008-11-14 Thread Phil Thompson
On Thu, 13 Nov 2008 16:58:01 -0800 (PST), chris3110
<[EMAIL PROTECTED]> wrote:
> Hi Phil, 
> 
> I've compiled the following snapshots 
> 
> PyQt-x11-gpl-4.4.4-snapshot-20081101 
> sip-4.7.8-snapshot-20081102 
> 
> and I still have a segfault.  I'm still using python 2.5 though. 
> 
> Is there a way to trace the source of the pb somehow ? 

I think you'd need to debug it at the C++ level.

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Crash (segfault) when using PyQt4 Qthread

2008-11-13 Thread chris3110


Hi Phil, 

I've compiled the following snapshots 

PyQt-x11-gpl-4.4.4-snapshot-20081101 
sip-4.7.8-snapshot-20081102 

and I still have a segfault.  I'm still using python 2.5 though. 

Is there a way to trace the source of the pb somehow ? 

Thanks, 
Christian


Phil Thompson-5 wrote:
> 
> On Thu, 30 Oct 2008 15:25:08 -0700 (PDT), chris3110
> <[EMAIL PROTECTED]> wrote:
>> Hi there,
>> 
>> I'm getting a systematic crash when trying to log the output of a Qthread
>> to
>> a parent window. I'm using Qt 4 on Fedora Core 9 with Python 2.5.1:
>> 
>>>rpm -q PyQt4 python
>> PyQt4-4.4.2-2.fc9.i386
>> python-2.5.1-26.fc9.i386
>> 
>> The following sample code crashes after a few iterations when clicking in
>> and out of the log window, moving it around, etc... sufficiently.  If you
>> don't touch the window at all it doesn't crash though.
>> 
>> Can someone explain what's going on here ?  Is there something wrong with
>> my
>> threading architecture ?  I guess the code should not give a segfault
>> anyway.
> 
> Works fine for me with current snapshots and Python 2.6.
> 
> Phil
> ___
> 

-- 
View this message in context: 
http://www.nabble.com/Crash-%28segfault%29-when-using-PyQt4-Qthread-tp20255394p20492875.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Crash (segfault) when using PyQt4 Qthread

2008-11-01 Thread Phil Thompson
On Thu, 30 Oct 2008 15:25:08 -0700 (PDT), chris3110
<[EMAIL PROTECTED]> wrote:
> Hi there,
> 
> I'm getting a systematic crash when trying to log the output of a Qthread
> to
> a parent window. I'm using Qt 4 on Fedora Core 9 with Python 2.5.1:
> 
>>rpm -q PyQt4 python
> PyQt4-4.4.2-2.fc9.i386
> python-2.5.1-26.fc9.i386
> 
> The following sample code crashes after a few iterations when clicking in
> and out of the log window, moving it around, etc... sufficiently.  If you
> don't touch the window at all it doesn't crash though.
> 
> Can someone explain what's going on here ?  Is there something wrong with
> my
> threading architecture ?  I guess the code should not give a segfault
> anyway.

Works fine for me with current snapshots and Python 2.6.

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Crash (segfault) when using PyQt4 Qthread

2008-10-30 Thread chris3110

Hi there,

I'm getting a systematic crash when trying to log the output of a Qthread to
a parent window. I'm using Qt 4 on Fedora Core 9 with Python 2.5.1:

>rpm -q PyQt4 python
PyQt4-4.4.2-2.fc9.i386
python-2.5.1-26.fc9.i386

The following sample code crashes after a few iterations when clicking in
and out of the log window, moving it around, etc... sufficiently.  If you
don't touch the window at all it doesn't crash though.

Can someone explain what's going on here ?  Is there something wrong with my
threading architecture ?  I guess the code should not give a segfault
anyway.

Thanks for your help,
Chris

snip---snip---
#!/usr/bin/python

import sys
import logging
import time
from PyQt4 import QtGui, QtCore, uic
from PyQt4.QtCore import QString, QThread
from PyQt4.QtGui import *

logging.basicConfig(level=logging.INFO)

class Page:
def __init__(self):
self.log = logging.getLogger('u.crawler')

def analyze(self):
for i in xrange(30):
self.log.info('Line %d', i)
time.sleep(2)

class CrawlerThread(QThread):
def __init__(self, page):
self.page = page
QThread.__init__ (self)

def run(self):
page = self.page
page.log.info('Starting')
page.analyze()

class WindowLogger(logging.Handler):
def __init__(self, window):
self.window = window
logging.Handler.__init__(self)

def emit(self, record):
self.window.appendPlainText(record.getMessage())


(urlFormUi, urlFormBase) = uic.loadUiType('urlForm.ui')

class UrlCrawler(urlFormUi, urlFormBase):

threadList = []

def __init__(self):
urlFormBase.__init__(self)
self.setupUi(self)

self.log = logging.getLogger('u.crawler')
self.log.addHandler(WindowLogger(self.winlog))

def accept(self):
thread = CrawlerThread(Page())
UrlCrawler.threadList.append(thread)
thread.start()

def reject(self):
self.close()

def closeEvent(self, event):
event.accept()


if __name__ == "__main__":
app = QtGui.QApplication([])
app.main = UrlCrawler()
app.main.show()
sys.exit(app.exec_())
snip---snip---

You'll also need the following urlForm.ui file in ordre to run the sample. 
Click "Ok" to start the thread.

snip---snip---

 dialog
 
  
   
0
0
435
472
   
  
  
   Test
  
  
   

 250
 10
 181
 32

   
   
Qt::Horizontal
   
   
QDialogButtonBox::Cancel|QDialogButtonBox::Ok
   
  
  
   

 10
 50
 421
 411

   
   
Qt::ScrollBarAlwaysOff
   
   
true
   
  
 
 
 
  
   buttonBox
   accepted()
   dialog
   accept()
   

 248
 254


 157
 274

   
  
  
   buttonBox
   rejected()
   dialog
   reject()
   

 316
 260


 286
 274

   
  
 

snip---snip---

-- 
View this message in context: 
http://www.nabble.com/Crash-%28segfault%29-when-using-PyQt4-Qthread-tp20255394p20255394.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt