Run a python function every second
<p>What I want is to be able to run a function every second, irrelevant of how long the function takes (it should always be under a second). I've considered a number of options but not sure which is best.</p>

<p>If I just use the delay function it isn't going to take into account the time the function takes to run.</p>

<p>If I time the function and then subtract that from a second and make up the rest in the delay it's not going to take into account the time calculations.</p>

<p>I tried using threading.timer (I'm not sure about the ins and outs of how this works) but it did seem to be slower than the 1s.</p>

<p>Here's the code I tried for testing threading.timer:</p>

<pre><code>def update(i):
    sys.stdout.write(str(i)+'\r')
    sys.stdout.flush()
    print i
    i += 1
    threading.Timer(1, update, [i]).start()
</code></pre>

<p>Is there a way to do this irrelevant of the length of the time the function takes?</p>
