A clock based on LSL local_clock

class Clock[source]

allows to keep track of time

reset the clock with reset(), and get the time since this reset with now(). Measure intermediate times with tick(), which return time since last call of tick(), or

each call of tick() updates the cumulative time since the last call of reset(). If you don’t want to add the time measured, use pause()


return the cumulative time passed since the last call of reset()


reset the clock

resets the counter keeping track of the cumulative time spend since instantiaion or the last call of reset()


Sleep for duration in seconds

blocking is slightly more accurate than non-blocking sleep, e.g. as available with time.sleep() from the stdlib. There is one disadvantage of this kind of busy sleep: it can cause slight oversleeping, as there is an overhead of the function being called and returning, which is not accounted for. See sleep_debiased() for an alternative sleep with asymptotic minimisation of the error.


duration (float) – how many seconds to sleep blocking


duration – the time in seconds spent sleeping

Return type



Sleep for duration in seconds with attempts for debiasing`

sometimes, you execute some other commands, and these commands have a variable runtime. If we would naively sleep everytime for n seconds afterwards, we would inherit this jitter. By using tick() before these commands, and sleep_debiased() after these commands, we can normalize the runtime to a fixed period (as long as the sleep duration is longer than the runtime of the commands).

Additionally, this function keeps track of any oversleeping or undersleeping, and will minimize the temporal error asymptotically


duration – the time in seconds spent sleeping since the last call of tick() or sleep_debiased().

Return type



This example shows how we can regularize the time spent in each cycle to 200ms in spite of there being an element of random runtime

import time
import random
from reiz.time import Clock
clock = Clock()
t = 0.
msg = "{0:3.5f}, {1:3.5f}, {2:3.5f}, slept for {3:3.5f}s"
for i in range(1, 11):
    dt = clock.sleep_debiased(0.2)
    t += dt
    print(msg.format(i*0.2,, t, dt))

time since last call of tick()


delta_t – time passed in seconds since the last call of tick() or pause(). This is time counting into the cumulative time

Return type



time in seconds (usually since computer boot) according to LSL

clock = <reiz.time.Clock object>

a default Clock instance ready for your experiment