POLL in different OSes

Rich Harkins rharkins at thinkronize.com
Tue Oct 23 22:24:31 CEST 2001

If not a true poll emulator, I would like to see a C overlay on select that
would handle C-level selectable objects that would have flags on the objects
managed by C.  This would mean that I wouldn't have to feed Pyhton lists to
select nor make select return three (possibly brand-spankin' new) lists as a
result.  The way it would work in my twisted little universe is something
like this:

Create the polled objects...
>>> obj1=makepolled(fd1)
>>> obj2=makepolled(fd2)

Create the poller and add the polled...
>>> poller=makepoller()
>>> poller.addpolled(obj1)
>>> poller.addpolled(obj2)

Enable the events I want to know about...
>>> obj1.enable(PL_READ)
>>> obj2.enable(PL_WRITE)

Poll 'em...
>>> poller.poll()

Test the result...
>>> if obj1.has(PL_READ):
>>>   # Read from obj1
>>> if obj2.has(PL_WRITE):
>>>   # Write to obj2

This is more code, yes, than select but it could be implemented using either
C-select or C-poll depending on OS coditions.  More importantly, lists did
not need to be fed to the poller nor does the poller produce new lists in
its operation.  This should be a big win in performance (I think) over the
traditional Python select mechanism.  I don't know the internals of the
Python implementation layer for select but I suspect this is the case.

Oh well, just wishful thinking...

More information about the Python-list mailing list