Events and file polling in a C extension

Dirk Thierbach dthierbach at
Sat Oct 23 20:25:53 CEST 2004

Donn Cave <donn at> wrote:
> Quoth Dirk Thierbach <dthierbach at>:

> So what would you do after select() returns with I/O ready?  Can
> the library then read and parse, and return the result?


> I would stay away from threads unless you have a strong need for
> concurrency that isn't already satisfied with select/poll.  

So would I, but at the moment I don't see how, unless Python supports
some sort of event handling. 

> It seems to me the simplest thing by far would be the arrangement I
> suggested above,

Which one? Handling select in the main program? That doesn't work,

> Python doesn't come with an event handler model, except when used
> with say a graphic toolkit - so for example Python/Tk will (I
> assume) look a lot like Tcl/Tk in this respect.

... I am exactly after something that looks like Python/Tk with
respect to Tk-bindings. I want to create an object, let the main
program do some bindings on that object, and then the main program
can go on to do whatever it likes. The object should dispatch any
events that arrive on the file descriptor by invoking the bindings,
just like the widget bindings in Python/Tk.

Of course I could create some sort of main loop myself, but that
seems inelegant and not portable. After all, Python/Tk doesn't
require you to call some sort of main loop, too.

- Dirk

More information about the Python-list mailing list