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


Groups > comp.lang.python > #81617

Re: Fwd: Python Signal/Slot + QThred code analysis

Date 2014-11-26 21:11 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Fwd: Python Signal/Slot + QThred code analysis
References (7 earlier) <5474C889.5090503@mrabarnett.plus.com> <CAAp0bGtv13QaPhfTx+tzSe6ZpQ9RCLiWrG1Cv+qfEw3JZ41o9g@mail.gmail.com> <547545CF.60208@gmail.com> <CAAp0bGuMRmEXXFpHaVx0MBoQ72N3MYXYwnnxpS58w-LSV6vTdw@mail.gmail.com> <5476A134.7050407@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16360.1417061524.18130.python-list@python.org> (permalink)

Show all headers | View raw


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@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

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


Thread

Re: Fwd: Python Signal/Slot + QThred code analysis Michael Torrie <torriem@gmail.com> - 2014-11-26 21:11 -0700

csiph-web