how do you implement a reactor without a select?

Michele Simionato michele.simionato at gmail.com
Mon May 7 11:34:29 EDT 2007


On May 7, 4:39 pm, a... at mac.com (Alex Martelli) wrote:
> Michele Simionato <michele.simion... at gmail.com> wrote:
> > I wonder if real mainloops are done in this way and how bad/good is
> > this implementation compared to a serious one. Any suggestion/hint/
> > advice is well appreciated. Thanks,
>
> Module sched in Python's standard library may suggest one clearly-better
> approach: when you know in advance when future events are scheduled for,
> sleep accordingly (rather than polling every millisecond).  sched's
> sources are simple enough to study, and its architecture clean and
> strong enough that it's easy to extend to other cases, e.g. where
> previously-unscheduled events may be delivered from other threads,
> without necessarily hacking the sources.
>
> Specifically, sched implements the Dependency Injection DP: rather than
> just calling time.time and time.sleep, it accepts those two callables
> upon initialization.  This makes it easy, among many other
> customizations, to pass instead of time.sleep a user-coded callable
> (typically a bound method) that "sleeps" by a wait-with-timeout on a
> Queue (so that other threads, by putting an event on the Queue in
> question, immediately wake up the scheduler, etc, etc).
>
> Alex

I know about sched (it was the first thing I looked at): the problem
is that sched
adopt a blocking approach and it basically requires threads, whereas I
wanted to
avoid them. Diez B. Roggisch's reply is closer to my expectations:

>> Most probably the OS will have specialized APIs (or some
>> wrapper lib has) that allow for reactor registration for events of different
>> kinds including timers.

But what kind of specialized API do I have at my disposition for
timers on Linux?
It looks like this is the question I should have asked the first
time ;)


    Michele Simionato




More information about the Python-list mailing list