Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81364

Python Signal/Slot + QThred code analysis

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <juan0christian@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'continuation': 0.07; 'subject: + ': 0.07; 'subject:code': 0.07; "'')": 0.09; '*args,': 0.09; '__init__': 0.09; 'apis': 0.09; 'here?': 0.09; 'option,': 0.09; 'python': 0.11; 'def': 0.12; 'books': 0.15; '**kwargs)': 0.16; '**kwargs):': 0.16; 'choice,': 0.16; 'does,': 0.16; 'emit': 0.16; 'soup': 0.16; 'stuff.': 0.16; 'subject:analysis': 0.16; 'threads.': 0.16; 'things.': 0.19; 'later': 0.20; 'thanks.': 0.20; 'import': 0.22; 'question': 0.24; 'this:': 0.26; 'pass': 0.26; 'subject:/': 0.26; 'code:': 0.26; 'topic': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'getting': 0.31; 'requests': 0.31; 'class': 0.32; 'run': 0.32; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'data,': 0.36; 'doing': 0.36; "i'll": 0.36; 'so,': 0.37; 'to:addr:python-list': 0.38; 'anything': 0.39; 'explain': 0.39; 'skip:b 40': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'read': 0.60; 'signal': 0.60; 'then,': 0.60; 'entire': 0.61; 'first': 0.61; 'real': 0.63; 'more': 0.64; 'talking': 0.65; 'url:user': 0.65; 'here': 0.66; 'answered,': 0.84; 'completely,': 0.84; '"how': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=l1wqgFi7lkHAMhE/z0LREFZkXzcceCnv/3ybxWsCnaw=; b=iTkXdyYquQbDA8/NzYeVqWkeNNR0Ja8ulf4E2VQSGfqEPknbqD5GrlxduFZMU/ZcYr F/mY776iuL2LS7UXMyt+UG+tSxwqyjKA1Su6NwI6SaaE8lMF+DYfRiDiyaRPV6+DQcF5 eOYRkCSLBD8XjrvwtLRwDkPXitH4Ym/H8bKtNSlaihqWukX5n+t3XxEo+yi3huhIBoBN 2Z8cWAMCu/JqvWy5rZpldTPb4d/rUxX+p/55qGKBLhe7NzN+1VrEJI7KnqMjWzhKSQL5 0939hbwkRRUFUaXj1XNwB9zi6vHb9ainTBRWn8upKidQYnba9qywDeLLZPaHi/tFEe8z sn4Q==
X-Received by 10.224.121.1 with SMTP id f1mr1529023qar.76.1416750271715; Sun, 23 Nov 2014 05:44:31 -0800 (PST)
MIME-Version 1.0
From Juan Christian <juan0christian@gmail.com>
Date Sun, 23 Nov 2014 13:44:31 +0000
Subject Python Signal/Slot + QThred code analysis
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=001a11c1ee24ae5e2a050886e020
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16182.1416750280.18130.python-list@python.org> (permalink)
Lines 89
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416750280 news.xs4all.nl 2947 [2001:888:2000:d::a6]:33179
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81364

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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 = 'http://www.myurl.com/user/' + uid

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

    with soup.select('div.stat_box div.value')[0].get_text().replace(',',
'') as a, soup.select('div.stat_box div.value')[1].get_text() as b:
        self.info_a = a
        self.info_b = b

    self.received.emit(self)

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
uid.

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
want.

Did I think correctly, can I do anything better here? Many thanks.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Python Signal/Slot + QThred code analysis Juan Christian <juan0christian@gmail.com> - 2014-11-23 13:44 +0000

csiph-web