13.5. Time manipulation

class Clock(start=0.0, stop=1.0, dt=0.001)

Clock class

Examples:

>>> clock = Clock(start=0.0, stop=1.0, dt=0.1)
>>> @clock.tick
>>> def tick(time):
...    print 'timer tick at time %.3f' % time
>>> clock.run()
run(start=None, stop=None, dt=None)

Run the clock.

Parameters

start : float
Start time
stop : float
Stop time
dt : float
Time step resolution
stop

Clock stop time.

reset()

Reset clock

clear()

Remove all timers

add(func, dt=None, order=0, start=None, stop=None)

Add a new timer to the timer list

Parameters

func : function(time)
Function to be added
dt : float or None
Time interval between each function call. If not timestep is given, clock resolution (clock.dt) is used.
order : int
In case several timers share the same time interval, those with lower order are called first.
remove(func, dt=None)

Remove a given timer from the timer list

Parameters

func : function(time)
Function to be removed
dt : float or None
Function timestep (as it was given when this function has been added to the timer list). If not timestep is given, clock resolution (clock.dt) is used.

Notes

A same function can be added with several different timesteps. It is this necessary to specify which timer (using timestep) is to be removed.

time

Current time

start

Clock start time

dt

Clock resolution.