Python Signal/Slot + QThred code analysis
juan0christian at gmail.com
Sun Nov 23 14:44:31 CET 2014
This is a continuation of my other topic "How to access Qt components
loaded from file", it was getting big and the focus changed completely, the
real question there was already answered, and we were talking about
signal/slot, QThred and other things.
So, I read on the web (didn't find books talking about QThred, Signal/Slot)
and I came up with this code:
from PySide.QtCore import QObject, QThread, Signal
class Outpost(QObject, QThread):
received = Signal()
def __init__(self, uid, *args, **kwargs):
self.url = 'http://www.myurl.com/user/' + uid
soup = bs4.BeautifulSoup(requests.get(self.url).text)
with soup.select('div.stat_box div.value').get_text().replace(',',
'') as a, soup.select('div.stat_box div.value').get_text() as b:
self.info_a = a
self.info_b = b
Is this code good?
I'll explain what I think this code does, when I was doing this: First I
created my custom signal, 'received'. Then I made my __init__ just to set a
Then, the run func, I read that's the one that will run when working with
threads. Here I set the soup and I get the page content using requests,
that's the part that will take more time.
Then I use bs4 to set my data, and yes, I know that getting data this way
isn't the best option, but I don't have other choice, they don't give APIs
for this stuff.
Later I emit my signal when I have everything set and I pass the entire
class with it so I can call the 'var.info_a' and 'bar.info_b' wherever I
Did I think correctly, can I do anything better here? Many thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list