[Stackless] non-blocking IO in uthreads

Bernd Rinn Bernd.Rinn at epost.de
Fri Feb 9 19:04:16 CET 2001


On Fri, Feb 09, 2001 at 12:25:05PM -0500, Will Ware wrote:
> << The first code
> snippet increases the load to 10% CPU usage, the second code snippet
> to about 90% CPU-usage. I am not only concerned about what the other
> uthreads get from the CPU but about the system as a whole. >>
> 
> I can see a couple of options. You can try nice-ing your Python session.
> Another possibility is to use uthread.wait(), which takes an argument
> in seconds (a floating-point number, I don't recall what the typical
> resolution is). Using wait() is probably the way you want to go, but
> you'll probably need some empirical tinkering to arrive at a good time
> delay. See if this helps:
> 
>     while timeout < 0 or time() < tmax:
>         uthread.wait(.1)
>         r,w,e = select(iwtd, owtd, ewtd, dt)
>         if r or w or e: break
>     return r,w,e
> 
> The microthread calling nbselect() will block for 0.1 seconds before
> calling select(), consuming no CPU time. If all your other microthreads
> are also blocked at that time, the CPU will be made available for other
> tasks. (This innovation courtesy of Mike Fletcher.)

Thanks alot! This solves my problem. I get what I want when setting
dt=0 (polling) and choosing a delay of 0.5 to 1 second, for example

def nbselect(iwtd, owtd, ewtd, timeout=-1):
    from select import select
    from time import time
    from uthread9 import wait
    r,w,e = select(iwtd, owtd, ewtd, 0)
    if r or w or e: return r,w,e
    tmax = time() + timeout
    while timeout < 0 or time() < tmax:
        r,w,e = select(iwtd, owtd, ewtd, 0)
        if r or w or e: return r,w,e
        wait(0.5)


(In my last mail I confused the time spend by another microthread and
the time spend by uthread.wait() when stating that uthread.wait() is
``rather expensive''.)

Regards,

Bernd

-- 
Bernd Rinn
Fakultät für Physik
Universität Konstanz

Tel. 07531/88-3812, 
e-mail: Bernd.Rinn at uni-konstanz.de
PGP-Fingerprint: 1F AC 31 64 FF EF A9 67  6E 0D 4C 26 0B E7 ED 5C
_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless



More information about the Stackless mailing list