Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   PyQt and async I/O (http://www.velocityreviews.com/forums/t319076-pyqt-and-async-i-o.html)

djw 07-01-2003 09:01 PM

PyQt and async I/O
 
Greetings-

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

http://aspn.activestate.com/ASPN/Coo...n/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


Andrew Bennetts 07-02-2003 01:23 AM

Re: PyQt and async I/O
 
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.




All times are GMT. The time now is 01:13 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57