Michele Simionato <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list