PyQt and async I/O

Discussion in 'Python' started by djw, Jul 1, 2003.

  1. djw

    djw Guest

    Greetings-

    I was looking at the ASPN recipe for async I/O and Tkinter:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965

    I am interested in using the recipe that is provided in the comments section
    for PyQt courtesy of Laura Creighton.

    I have a question though....

    In the code, it says:

    "One important thing to remember is that the thread has to yield
    control."

    That appears in this code (the thread that will contain the async I/O):

    def workerThread1(self):
    """
    This is where we handle the asynchronous I/O. For example, it may be
    a 'select()'.
    One important thing to remember is that the thread has to yield
    control.
    """
    while self.running:
    # To simulate asynchronous I/O, we create a random number at
    # random intervals. Replace the following 2 lines with the real
    # thing.
    time.sleep(rand.random() * 0.3)
    msg = rand.random()
    self.queue.put(msg)


    If you were to use asyncore for this async I/O, there is no yielding that I
    can see. Select() doesn't yield, and there is no time.sleep() in the
    asyncore.loop() code. Even if I were to add a time.sleep() to the loop,
    wouldn't the fact that select() blocks for some timeout value (default=30.0
    sec) imply that it would only yield after the select() timed out each time
    through the loop? That would seem to make for a pretty unresponsive UI.

    Hopefully somebody can clue me into understanding this.

    Thanks,

    Don
     
    djw, Jul 1, 2003
    #1
    1. Advertising

  2. On Tue, Jul 01, 2003 at 02:01:43PM -0700, djw wrote:
    [...]
    >
    > If you were to use asyncore for this async I/O, there is no yielding that I
    > can see. Select() doesn't yield, and there is no time.sleep() in the
    > asyncore.loop() code. Even if I were to add a time.sleep() to the loop,
    > wouldn't the fact that select() blocks for some timeout value (default=30.0
    > sec) imply that it would only yield after the select() timed out each time
    > through the loop? That would seem to make for a pretty unresponsive UI.
    >
    > Hopefully somebody can clue me into understanding this.


    Twisted has support for Qt -- see the 'twisted.internet.qtreactor' module.
    That might give you some ideas; alternatively, you could just use Twisted
    and stop worrying ;)

    -Andrew.
     
    Andrew Bennetts, Jul 2, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob Johnson
    Replies:
    4
    Views:
    1,041
    George Durzi
    Nov 13, 2003
  2. Jay
    Replies:
    0
    Views:
    377
  3. DotNetShadow
    Replies:
    0
    Views:
    1,586
    DotNetShadow
    Feb 7, 2005
  4. ulysses
    Replies:
    4
    Views:
    802
    Werner Schiendl
    Oct 22, 2003
  5. Steven
    Replies:
    0
    Views:
    395
    Steven
    Nov 30, 2005
Loading...

Share This Page