Powernap is was a little python module for accurate sleeping.
Now it's an extension and works even better.
Why
Python's time.sleep() function is pretty inaccurate. Definitely not accurate enough for music, games or graphics. It can sleep too long or too short, and usually does.
How
Using Linux's real-time clock (RTC) allows for more accurate timing. This wraps all the messy RTC stuff and provides nap(), which performs the same job as sleep(), but more accurately. Even more useful, it provides rnap(), which is a padding nap. That is, if you call rnap(30), it will nap for however many milliseconds are required to make the time since the last nap 3o milliseconds. get it?
rtc_on() sets up the real-time clock business, rtc_off() turns it off. As a bonus, it also switches the scheduler to SCHED_FIFO. One day it might switch back when you turn off the clock...
No guarantees that this will fail cleanly with a non-rt kernel - let me know if you have trouble with it.
Documentation
Read the documentation (v. 30).
Download
Download powernap v. 30. This is an extension written with C and Pyrex, requires real-time capabilities (such as with the real-time LSM).
Download the old pure-python version. You need to switch to real-time (SCHED_FIFO, ...) yourself with this one. This is version 9. I can't be bothered translating SVN version numbers into the usual version number convention.










