Higher level abstraction on select()

Panu A Kalliokoski pkalliok at cc.helsinki.fi
Wed May 30 06:02:32 EDT 2001


Hello all, I've developed a Python module (in Python) to make somewhat
higher abstraction over select.select(). The package is called
"selecting". The package is somewhat similar to asyncore, but has many
advantages over it:

- It's made in OO fashion, so that one may use _both_ select managers
_and_ threads (asyncore uses globals, making it impossible to have many
select managers);

- Event queues, which allow you to schedule events that should happen
sometime in the future (nicely synced with select())

- Channel interfaces. It's possible to make many different channels as
long as they have a fd to select() on; with this, you can implement, for
example, inter-thread locking with pipes.

- Some support for TKinter (mostly untested)

- Simpler buffering scheme, which makes it unnecessary to use unblocking
fd's, and might even give some speed

- No exception handling (I found exception packing of asyncore to be a
real nuisance)

- Clearer (?) division of responsibility: the API of channel handlers,
etc.  (asyncore puts part of message handling into the socket wrapper)

The package is available for inspecting at 
http://sange.fi/~atehwa-u/selecting-0.8/	and
http://sange.fi/~atehwa-u/selecting-0.8.tar.gz

The package is quite well tested and has been used to build ircd-style
daemons, but more testing and comments are always welcome. Especially I'd
like to see the following to be included in the package in the future:

- Good connectivity to TKinter. This would make TKinter one channel in a
select manager, not a special select manager that registers channels to
TKinter. The current solution is bad because it means slightly different
API for TKSelectManager from SelectManager and because TKinter's fd
handling API is insufficient for handling all situations.

- More channel types to provide, for example, Linda for a couple of
threads via selecting.

- Protocol modules for to use as ready channel handlers.

- Buffered channels with many queues with different throughput priority.

But especially, I'd like everybody to try the package out and tell me
what they think of it. I think the module should be included in the
standard Python distribution, if there's not already something better
than asyncore.

Panu Kalliokoski




More information about the Python-list mailing list