On Wed, Jul 23, 2008 at 12:33:57PM +0100, Michal Pryc wrote:
> Canceling the operation is one thing and nice smooth progress is another
> one.
>
> The chunk is more important for the progress information, so the user will
> be able to see that something is being downloaded.
True, but if you can't display that progress in a timely fashion, then
you've also failed. I would think that for a GUI, timing is more important
than anything else -- show the user what's going on, even if nothing has
happened.
Anyway, here's the test program:
#!/usr/bin/python
import select
import threading
import sys
import time
import os
def do_select(pipe_r):
in_time = time.time()
while time.time() - in_time < 5:
rem_time = 5 - (time.time() - in_time)
inl, outl, errl = select.select([sys.stdin, pipe_r], [], [],
rem_time)
if pipe_r in inl:
pipe_s = os.read(pipe_r, 100)
print "pipe says:", pipe_s
if pipe_s == "stop!":
print "Stopping"
return
print "Hey!"
pipe_r, pipe_w = os.pipe()
pipe_r2, pipe_w2 = os.pipe()
t1 = threading.Thread(target=do_select, name="select thread one",
args=[pipe_r])
t2 = threading.Thread(target=do_select, name="select thread two",
args=[pipe_r2])
t1.start()
t2.start()
time.sleep(2)
os.write(pipe_w, "stop!")
os.write(pipe_w2, "stop, sir!")
t1.join()
t2.join()
The idea is that one "network thread" waits five seconds for data shows up,
but is interrupted after two by the main thread. The other thread isn't
actually interrupted, so it restarts. Unfortunately, I can't find a way
for python to return the remaining timeout, so I have to hack it in on my
own, which is undoubtedly less efficient, but probably is okay for the gui.
Danek
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss