Python Signal/Slot + QThred code analysis

Juan Christian juan0christian at
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:

Python 3.4.2
PySide 1.2.2

from PySide.QtCore import QObject, QThread, Signal
import requests
import bs4

class Outpost(QObject, QThread):
    received = Signal()

def __init__(self, uid, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.url = '' + uid

def run(self):
    soup = bs4.BeautifulSoup(requests.get(self.url).text)

    with'div.stat_box div.value')[0].get_text().replace(',',
'') as a,'div.stat_box div.value')[1].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...
URL: <>

More information about the Python-list mailing list