Fwd: Python Signal/Slot + QThred code analysis

Michael Torrie torriem at gmail.com
Wed Nov 26 23:11:56 EST 2014


On 11/26/2014 08:57 PM, Michael Torrie wrote:
> On 11/26/2014 02:55 PM, Juan Christian wrote:
>> On Wed Nov 26 2014 at 1:16:11 AM Michael Torrie <torriem at gmail.com> wrote:
>> You're going to have to post a complete, but small, code example, I
>> think. Working with fragments of code is very difficult if not
>> impossible to assist with, resulting in obtuse, obvious replies from folks.
>>
>> As asked, here is all the code:
>>
>> outpost module: http://pastebin.com/H3K9UUWi
>> main module: http://pastebin.com/dFzums9W
>>
>> I was trying to do other things there but I ended up screwing everything.
> 
> I'm sorry I can't run the code you posted.  I don't seem to have any
> modules named "request" on Python 3 or Python 2 and your Trader.py seems
> to require it.
> 
> You might want to remove the url downloading and Beautiful Soup stuff
> and put in some kind of nop loop instead to simulate it.  For example,
> in the Trader module you can remove everything in run() and just have it
> return dummy values, maybe putting in a delay to simulate the work of
> downloading and parsing.
> 
> Just an observation from looking at the main module code.
> You only need to attach a callback to a signal once.  output_slot()
> seems to attach the callback each and every time the timer fires.  This
> is surely wrong.
> 
> I'll give it some further study this evening.

Hmm, I hit a wall.  There's no main.ui file.  Can you rework your code
so that you have a single file (plus a separate ui file that's okay),
that simulates the url request, that I can execute easily.

Here's how you can simulate the web page load:
from PySide.QtCore import QObject, QThread, Signal
import random
import time


class Worker(QThread):
    def __init__(self, url, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.trades = 'NODATA'
        self.posts = 'NODATA'
        self.url = url
        self.start()

    def run(self):
        # simulate a web request by sleeping a random time and returning
        # random strings.
        time.sleep(random.random() * 2)
        self.trades = str(random.random() * 25)
        self.posts = str(random.random() * 100)
        return self




More information about the Python-list mailing list