select() interruption by signal

Tim O'Malley timo at bbn.com
Tue Oct 12 17:07:27 EDT 1999


hola.

Robert Longstaff writes:
 > In my app I have a select() call inside a continuous loop waiting for
 > asynchronous data input from various connected sources. As this call
 > blocks and I need to perform other mini tasks I have an alarm call
 > that fires every 2s that is reset inside its handler.

I'd advocate using the 4th parameter of select() instead of a signal.
The fourth parameter is a timeout, once that much time has elapsed
select() will return, even if no descriptors are ready.

Typically, I'll write something like:

    while 1:
        delay = time.time() - TimeOfNextTask
        if delay:
	    DoTask()
        else:
            r,w,e = select.select( fds, [], fds, delay )

            for F in r:
                handle_read()
            for F in e:
                handle_write()
        # done
    # done


best-o-luck!

-- 
.....................................................................
.   happy daze            .   Age and treachery will beat           .
.        -tim O           .       youth and skill every time.       .
.....................................................................




More information about the Python-list mailing list