Skip to main content

The 10ms OS pre-emption interval and sleep()

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.


Popular posts from this blog

Python: Multiprocessing: passing multiple arguments to a function

Write a wrapper function to unpack the arguments before calling the real function. Lambda won't work, for some strange un-Pythonic reason.

import multiprocessing as mp def myfun(a,b): print a + b def mf_wrap(args): return myfun(*args) p = mp.Pool(4) fl = [(a,b) for a in range(3) for b in range(2)] #mf_wrap = lambda args: myfun(*args) -> this sucker, though more pythonic and compact, won't work, fl)

Flowing text in inkscape (Poster making)

You can flow text into arbitrary shapes in inkscape. (From a hint here).

You simply create a text box, type your text into it, create a frame with some drawing tool, select both the text box and the frame (click and shift) and then go to text->flow into frame.


The omnipresent anonymous asked:
Trying to enter sentence so that text forms the number three...any ideas?
The solution:
Type '3' using the text toolConvert to path using object->pathSize as necessaryRemove fillUngroupType in actual text in new text boxSelect the text and the '3' pathFlow the text