Linux and Mac OS X have a 10ms preemption (scheduling) interval. This means that the python time.sleep command (often introduced in a polling loop to prevent the thread hogging the CPU) has a floor at 10ms i.e time.sleep(1), time.sleep(.5) and time.sleep(.01) will all work as expected, giving 1s, 500ms and 10ms delays. But time.sleep(.001) will give us a 10ms delay, not a 1ms delay.
There is a hack for linux systems using nanosleep, but the cleanest thing to do is to use Queues from the multiprocessing module, instead of polling loops. You can also use select, but that gets more messy.
There is a hack for linux systems using nanosleep, but the cleanest thing to do is to use Queues from the multiprocessing module, instead of polling loops. You can also use select, but that gets more messy.
Comments
Post a Comment