Events and file polling in a C extension

Dirk Thierbach dthierbach at gmx.de
Sat Oct 23 06:25:28 EDT 2004


I am writing an Python 2.3 extension in C, and I would like to create
events (Tk-style) from an external source. I use a library that
already parses the events into a C structure. This library can
also supply file ids for poll() or select() calls (all this is on
Linux, BTW). 

What's the preferred way to doing this? Can I register my own event
handlers to the Python runtime, including the file ids to poll/to do
select on, as in Tcl/Tk? Or do I have to create a new thread, and
do a blocking select/poll-call inside the thread? If yes, how much
attention do I have to pay to Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS?
E.g. use them as often as possible, or only at cricitical points?
How do I create a new thread with the C API, anyway? Or should I wrap
that into a Python module that calls some auxiliary functions
in the C module?

As I am comparatively new to Python and the C API, I would be glad for
some boilerplate C-code (if there is any available somewhere) I could
use as a starting point, so I don't have to re-invent the wheel myself
another time :-)

Thanks for any help,

- Dirk





More information about the Python-list mailing list