[Python-3000] iostack and sock2

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Jun 6 02:26:17 CEST 2006

tomer filiba wrote:
> I wrote:
>  > My current opinion on select-like functionality is
>  > that you shouldn't need to import a module for it at
>  > all. Rather, you should be able to attach a callback
>  > directly to a stream. Then there just needs to be
>  > a wait_for_something_to_happen() function somewhere
>  > (perhaps with a timeout).
> yes, that's how i'd do it, but then how would you wait for
> multiple streams?

   # somewhere in the program

   stream1.on_readable = handle_stream1

   # somewhere else

   stream2.on_readable = handle_stream2

   # and the main loop says

   while program_is_running():

The wait_for_streams function waits for activity on any
stream which has a callback, and calls it.

(BTW, I actually think this sort of functionality should
be part of the OS kernel, with event-driven programs and
libraries being so important nowadays. Sort of like being
able to define signal handlers for file descriptors instead
of having a small, fixed number of signals.)


More information about the Python-3000 mailing list