PyQt QThreadPool error

2010-01-07 Thread h0uk
Hello.

I have the following code:

#workers = {}
QtCore.QThreadPool.globalInstance().setExpiryTimeout
(30)
QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)
for i in range(1, int(userscnt) + 1):
work = wk.Worker(i)
# connect signals
work.mmShowCaptcha.connect(self.show_captcha_dlg)
work.log.connect(self.handle_log)
self.captcha_answer.connect(work.mmCaptchaAnswer)
work.setAutoDelete(True)
QtCore.QThreadPool.globalInstance().start(work)



On last line of code ( QtCore.QThreadPool.globalInstance().start
(work) ) i get an error:

SystemError: error return without exception set

What is wrong in my code??? Any advise???

Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt QThreadPool error

2010-01-07 Thread h0uk
On 8 янв, 01:02, "Diez B. Roggisch"  wrote:
> h0uk schrieb:
>
>
>
> > Hello.
>
> > I have the following code:
>
> >             #workers = {}
> >             QtCore.QThreadPool.globalInstance().setExpiryTimeout
> > (30)
> >             QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)
> >             for i in range(1, int(userscnt) + 1):
> >                 work = wk.Worker(i)
> >                 # connect signals
> >                 work.mmShowCaptcha.connect(self.show_captcha_dlg)
> >                 work.log.connect(self.handle_log)
> >                 self.captcha_answer.connect(work.mmCaptchaAnswer)
> >                 work.setAutoDelete(True)
> >                 QtCore.QThreadPool.globalInstance().start(work)
>
> > On last line of code ( QtCore.QThreadPool.globalInstance().start
> > (work) ) i get an error:
>
> > SystemError: error return without exception set
>
> > What is wrong in my code??? Any advise???
>
> The error is on C-level. AFAIK it occurs when a Python-C-function
> returns "NULL" without setting an exception.
>
> It's hard to say where it really occurs. I'd use a debug-build of PyQt,
> and possibly Python, and then investigate using gdb.
>
> Alternatively, what happens when you do some "dummy"-work that doesn't
> use signals and no other libraries?
>
> Diez

About some "dummy" code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import time

from PyQt4 import QtCore, QtGui

class Job(QtCore.QRunnable):
def __init__(self, name):
QtCore.QRunnable.__init__(self)
self._name = name

def run(self):
time.sleep(10)
print self._name

def autoDelete(self):
return self._auto

def setAutoDelete(self, auto):
self._auto = auto



if __name__ == "__main__":

app = QtGui.QApplication(sys.argv)

QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)

j = Job("Job-1")
j.setAutoDelete(True)
QtCore.QThreadPool.globalInstance().start(j)


Even this code not work. On the last line of code
( QtCore.QThreadPool.globalInstance().start(j) ) i get the error:

>> An unhandled win32 exception occured in python.exe

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt QThreadPool error

2010-01-07 Thread h0uk
On 8 янв, 02:25, "Diez B. Roggisch"  wrote:
> h0uk schrieb:
>
>
>
> > On 8 янв, 01:02, "Diez B. Roggisch"  wrote:
> >> h0uk schrieb:
>
> >>> Hello.
> >>> I have the following code:
> >>>             #workers = {}
> >>>             QtCore.QThreadPool.globalInstance().setExpiryTimeout
> >>> (30)
> >>>             QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)
> >>>             for i in range(1, int(userscnt) + 1):
> >>>                 work = wk.Worker(i)
> >>>                 # connect signals
> >>>                 work.mmShowCaptcha.connect(self.show_captcha_dlg)
> >>>                 work.log.connect(self.handle_log)
> >>>                 self.captcha_answer.connect(work.mmCaptchaAnswer)
> >>>                 work.setAutoDelete(True)
> >>>                 QtCore.QThreadPool.globalInstance().start(work)
> >>> On last line of code ( QtCore.QThreadPool.globalInstance().start
> >>> (work) ) i get an error:
> >>> SystemError: error return without exception set
> >>> What is wrong in my code??? Any advise???
> >> The error is on C-level. AFAIK it occurs when a Python-C-function
> >> returns "NULL" without setting an exception.
>
> >> It's hard to say where it really occurs. I'd use a debug-build of PyQt,
> >> and possibly Python, and then investigate using gdb.
>
> >> Alternatively, what happens when you do some "dummy"-work that doesn't
> >> use signals and no other libraries?
>
> >> Diez
>
> > About some "dummy" code:
>
> > #!/usr/bin/env python
> > # -*- coding: utf-8 -*-
>
> > import sys
> > import os
> > import time
>
> > from PyQt4 import QtCore, QtGui
>
> > class Job(QtCore.QRunnable):
> >    def __init__(self, name):
> >            QtCore.QRunnable.__init__(self)
> >            self._name = name
>
> >    def run(self):
> >            time.sleep(10)
> >            print self._name
>
> >    def autoDelete(self):
> >            return self._auto
>
> >    def setAutoDelete(self, auto):
> >            self._auto = auto
>
> > if __name__ == "__main__":
>
> >    app = QtGui.QApplication(sys.argv)
>
> >    QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)
>
> >    j = Job("Job-1")
> >    j.setAutoDelete(True)
> >    QtCore.QThreadPool.globalInstance().start(j)
>
> > Even this code not work. On the last line of code
> > ( QtCore.QThreadPool.globalInstance().start(j) ) i get the error:
>
> >>> An unhandled win32 exception occured in python.exe
>
> Hm. I suggest you take this to the PyQt mailinglist. Phil Thompson is
> very responsive.
>
> Diez

Thanks you, Diez. Thanks for your time.
I already wrote to PyQt mailing list, but yet no get answer.

I will be waiting and try to write Phil Thompson.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt QThreadPool error

2010-01-07 Thread h0uk
On 8 янв, 03:02, Phil Thompson  wrote:
> On Thu, 7 Jan 2010 13:03:24 -0800 (PST), h0uk 
> wrote:
>
> > On 8 янв, 01:02, "Diez B. Roggisch"  wrote:
> >> h0uk schrieb:
>
> >> > Hello.
>
> >> > I have the following code:
>
> >> >             #workers = {}
> >> >             QtCore.QThreadPool.globalInstance().setExpiryTimeout
> >> > (30)
> >> >            
> >> > QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)
> >> >             for i in range(1, int(userscnt) + 1):
> >> >                 work = wk.Worker(i)
> >> >                 # connect signals
> >> >                
> >> > work.mmShowCaptcha.connect(self.show_captcha_dlg)
> >> >                 work.log.connect(self.handle_log)
> >> >                
> >> > self.captcha_answer.connect(work.mmCaptchaAnswer)
> >> >                 work.setAutoDelete(True)
> >> >                
>
> QtCore.QThreadPool.globalInstance().start(work)
>
>
>
>
>
> >> > On last line of code ( QtCore.QThreadPool.globalInstance().start
> >> > (work) ) i get an error:
>
> >> > SystemError: error return without exception set
>
> >> > What is wrong in my code??? Any advise???
>
> >> The error is on C-level. AFAIK it occurs when a Python-C-function
> >> returns "NULL" without setting an exception.
>
> >> It's hard to say where it really occurs. I'd use a debug-build of PyQt,
> >> and possibly Python, and then investigate using gdb.
>
> >> Alternatively, what happens when you do some "dummy"-work that doesn't
> >> use signals and no other libraries?
>
> >> Diez
>
> > About some "dummy" code:
>
> > #!/usr/bin/env python
> > # -*- coding: utf-8 -*-
>
> > import sys
> > import os
> > import time
>
> > from PyQt4 import QtCore, QtGui
>
> > class Job(QtCore.QRunnable):
> >    def __init__(self, name):
> >            QtCore.QRunnable.__init__(self)
> >            self._name = name
>
> >    def run(self):
> >            time.sleep(10)
> >            print self._name
>
> >    def autoDelete(self):
> >            return self._auto
>
> >    def setAutoDelete(self, auto):
> >            self._auto = auto
>
> > if __name__ == "__main__":
>
> >    app = QtGui.QApplication(sys.argv)
>
> >    QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)
>
> >    j = Job("Job-1")
> >    j.setAutoDelete(True)
> >    QtCore.QThreadPool.globalInstance().start(j)
>
> > Even this code not work. On the last line of code
> > ( QtCore.QThreadPool.globalInstance().start(j) ) i get the error:
>
> >>> An unhandled win32 exception occured in python.exe
>
> You aren't letting the thread run before exiting the program. Try adding...
>
>     app.exec_()
>
> ...after you call start().
>
> Also, I'm not sure what you are trying to achieve with your implementations
> of autoDelete() and setAutoDelete().
>
> Phil

Phil you right about app.exec_(). But situation is sligthly different.

I want to have more than one Job. I add these Jobs into QThreadPool
trough cycle. And I also want these Jobs to run  sequentially.

The following code illustrate what I mean:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import time

from PyQt4 import QtCore, QtGui

class Job(QtCore.QRunnable):
def __init__(self, name):
QtCore.QRunnable.__init__(self)
self._name = name

def run(self):
time.sleep(3)
print self._name


if __name__ == "__main__":

app = QtGui.QApplication(sys.argv)

QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)

for i in range(5):
j = Job("Job-" + str(i))
j.setAutoDelete(True)
QtCore.QThreadPool.globalInstance().start(j, i)
app.exec_()

After 5 cycle I get the same error:  An unhandled win32 exception
occured in python.exe.

How I can do it?? To run my Jobs sequentially???

Vardan.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ask how to use HTMLParser

2010-01-07 Thread h0uk
On 8 янв, 08:44, Water Lin  wrote:
> I am a new guy to use Python, but I want to parse a html page now. I
> tried to use HTMLParse. Here is my sample code:
> --
> from HTMLParser import HTMLParser
> from urllib2 import urlopen
>
> class MyParser(HTMLParser):
>     title = ""
>     is_title = ""
>     def __init__(self, url):
>         HTMLParser.__init__(self)
>         req = urlopen(url)
>         self.feed(req.read())
>
>     def handle_starttag(self, tag, attrs):
>         if tag == 'div' and attrs[0][1] == 'articleTitle':
>             print "Found link => %s" % attrs[0][1]
>             self.is_title = 1
>
>     def handle_data(self, data):
>         if self.is_title:
>             print "here"
>             self.title = data
>             print self.title
>             self.is_title = 0
> ---
>
> For the tag
> ---
> open article title
> ---
>
> I use my code to parse it. I can locate the div tag but I don't know how
> to get the text for the tag which is "open article title" in my example.
>
> How can I get the html content? What's wrong in my handle_data function?
>
> Thanks
>
> Water Lin
>
> --
> Water Lin's notes and pencils:http://en.waterlin.org
> Email: [email protected]

Hi.

Have you get errors or anything else??? What is wrong??

Vardan.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ask how to use HTMLParser

2010-01-07 Thread h0uk
On 8 янв, 08:44, Water Lin  wrote:
> I am a new guy to use Python, but I want to parse a html page now. I
> tried to use HTMLParse. Here is my sample code:
> --
> from HTMLParser import HTMLParser
> from urllib2 import urlopen
>
> class MyParser(HTMLParser):
>     title = ""
>     is_title = ""
>     def __init__(self, url):
>         HTMLParser.__init__(self)
>         req = urlopen(url)
>         self.feed(req.read())
>
>     def handle_starttag(self, tag, attrs):
>         if tag == 'div' and attrs[0][1] == 'articleTitle':
>             print "Found link => %s" % attrs[0][1]
>             self.is_title = 1
>
>     def handle_data(self, data):
>         if self.is_title:
>             print "here"
>             self.title = data
>             print self.title
>             self.is_title = 0
> ---
>
> For the tag
> ---
> open article title
> ---
>
> I use my code to parse it. I can locate the div tag but I don't know how
> to get the text for the tag which is "open article title" in my example.
>
> How can I get the html content? What's wrong in my handle_data function?
>
> Thanks
>
> Water Lin
>
> --
> Water Lin's notes and pencils:http://en.waterlin.org
> Email: [email protected]

I want to say your code works well
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ask how to use HTMLParser

2010-01-08 Thread h0uk
On 8 янв, 11:44, Water Lin  wrote:
> h0uk  writes:
> > On 8 янв, 08:44, Water Lin  wrote:
> >> I am a new guy to use Python, but I want to parse a html page now. I
> >> tried to use HTMLParse. Here is my sample code:
> >> --
> >> from HTMLParser import HTMLParser
> >> from urllib2 import urlopen
>
> >> class MyParser(HTMLParser):
> >>     title = ""
> >>     is_title = ""
> >>     def __init__(self, url):
> >>         HTMLParser.__init__(self)
> >>         req = urlopen(url)
> >>         self.feed(req.read())
>
> >>     def handle_starttag(self, tag, attrs):
> >>         if tag == 'div' and attrs[0][1] == 'articleTitle':
> >>             print "Found link => %s" % attrs[0][1]
> >>             self.is_title = 1
>
> >>     def handle_data(self, data):
> >>         if self.is_title:
> >>             print "here"
> >>             self.title = data
> >>             print self.title
> >>             self.is_title = 0
> >> ---
>
> >> For the tag
> >> ---
> >> open article title
> >> ---
>
> >> I use my code to parse it. I can locate the div tag but I don't know how
> >> to get the text for the tag which is "open article title" in my example.
>
> >> How can I get the html content? What's wrong in my handle_data function?
>
> >> Thanks
>
> >> Water Lin
>
> >> --
> >> Water Lin's notes and pencils:http://en.waterlin.org
> >> Email: [email protected]
>
> > I want to say your code works well
>
> But in handle_data I can't print self.title. I don't why I can't set the
> self.title in handle_data.
>
> Thanks
>
> Water Lin
>
> --
> Water Lin's notes and pencils:http://en.waterlin.org
> Email: [email protected]

I have tested your code as :

#!/usr/bin/env python
# -*- conding: utf-8 -*-

from HTMLParser import HTMLParser

class MyParser(HTMLParser):
title = ""
is_title = ""
def __init__(self, data):
HTMLParser.__init__(self)
self.feed(data)

def handle_starttag(self, tag, attrs):
if tag == 'div' and attrs[0][1] == 'articleTitle':
print "Found link => %s" % attrs[0][1]
self.is_title = 1

def handle_data(self, data):
if self.is_title:
print "here"
self.title = data
print self.title
self.is_title = 0


if __name__ == "__main__":

m  = MyParser(""" 
  
  
  
  
  
open article 
title
  
  
  
  Ask how to use HTMLParser
  
  
  
  Parametrs
  
  
  """)



All stuff printed and handled fine. Also, the 'print self.title'
statement works fine.
Try run my code.

Vardan.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt QThreadPool error

2010-01-08 Thread h0uk
On 8 янв, 16:27, Phil Thompson  wrote:
> On Thu, 7 Jan 2010 15:07:10 -0800 (PST), h0uk 
> wrote:
>
> ...
>
>
>
> > Phil you right about app.exec_(). But situation is sligthly different.
>
> > I want to have more than one Job. I add these Jobs into QThreadPool
> > trough cycle. And I also want these Jobs to run  sequentially.
>
> > The following code illustrate what I mean:
>
> > #!/usr/bin/env python
> > # -*- coding: utf-8 -*-
>
> > import sys
> > import os
> > import time
>
> > from PyQt4 import QtCore, QtGui
>
> > class Job(QtCore.QRunnable):
> >    def __init__(self, name):
> >            QtCore.QRunnable.__init__(self)
> >            self._name = name
>
> >    def run(self):
> >            time.sleep(3)
> >            print self._name
>
> > if __name__ == "__main__":
>
> >    app = QtGui.QApplication(sys.argv)
>
> >    QtCore.QThreadPool.globalInstance().setMaxThreadCount(1)
>
> >    for i in range(5):
> >            j = Job("Job-" + str(i))
> >            j.setAutoDelete(True)
> >            QtCore.QThreadPool.globalInstance().start(j, i)
> >    app.exec_()
>
> > After 5 cycle I get the same error:  An unhandled win32 exception
> > occured in python.exe.
>
> > How I can do it?? To run my Jobs sequentially???
>
> It's a PyQt bug. The workaround is not to use setAutoDelete() and instead
> keep an explicit reference to your Job instances - for example in a list of
> jobs.
>
> Phil

Thanks, Phil.
-- 
http://mail.python.org/mailman/listinfo/python-list