Events and file polling in a C extension

Josiah Carlson jcarlson at uci.edu
Sat Oct 23 18:32:26 EDT 2004


Josiah Carlson <jcarlson at uci.edu> wrote:
> I believe that most languages support event handling in one way or
> another. Here is one way...
> 
> def handle_event(event):
>     if event.typ == 'new_connection':
>         #handle a new connection
>     elif event.typ == ...
> 
> Or, if you want to use something that already has much of this designed
> and built for sockets, check out asyncore or asynchat.  Use
> asyncore.loop(timeout, 1) to poll the sockets every 1/100th of a second
> or so, and you should be good.

That is not to say that asyncore.loop(timeout, 1) will poll the sockets
every 100th a second, just that you should make that call about every
1/100th a second (timeout of 0 would be a true poll).

 - Josiah




More information about the Python-list mailing list