It is often required to repeatedly call a specific function or method with a certain time interval. This can be done using the class timer. See the example timerExample.py in the demo folder for what the timer can be used. The method or function can either be called once after a certain interval (single shot timer) or repeatedly with a given interval. In both cases, the variable that references the timer instance must always exist. Once it is destroyed, the timer is automatically stopped and deleted. Use the timer manager (menu scripts >> timer manager) to see a list of all active timer instances. This dialog also allows stopping or restarting these timers.
timer(interval, callbackFunc, argTuple=(), singleShot=False, name='', startAfterInit=True) → timer¶
Creates a new timer object for (continously) triggering a callback function
Creates a timer object that (continuously) calls a python callback function or method. The timer is active right from the beginning, hence, after creating this object. If
True, the callback function is triggered once after the interval is passed (denoted as timeout). Else, the callback is continuously triggered with the given interval.
Please note, that the timer objects may time out later than expected if Python is currently busy or the operating system is unable to provide the requested accuracy. In such a case of timeout overrun, the callback function is only triggered once, even if multiple timeouts have expired, and then will resume the original interval.
New in itom 4.1: Added optional
Time out interval in ms.
Python method (bounded) or function (unbounded) that should be called whenever the timer event raises.
Tuple of parameters passed as arguments to the callback function.
Defines if this timer only fires one time after its start (
True) or continuously (
Is the optional name of this timer. This name is displayed in the timer manager dialog (instead of the timer ID, if no name is given.
If this optional boolean is set to False the timer will not start after initialization. The timer can be started later by using timer.start().
>>> import time ... ... def callbackFunc(startTime: float, a: int): ... print("%.2f sec elapsed: %i" % (time.time() - startTime, a)) ... ... myTimer = timer(1000, callbackFunc, argTuple = (time.time(), 25))
1.00 sec elapsed: 25 2.01 sec elapsed : 25 3.01 sec elapsed : 25 4.01 sec elapsed : 25
isActive() → bool¶
Indicates if the timer is currently active.
Trueif the timer is running, otherwise
Sets the timer interval in ms.
This method sets the timeout interval in milliseconds. If the timer is started, the callback function is tried to be continously triggered whenever the interval expired.
Timeout interval in milliseconds.
If Python is currently busy, a timer event can also be triggered at a later time, if the same trigger event is not already in the execution queue.
Starts the timer.
This method starts or restarts the timer with its timeout interval. If the timer is already running, it will be stopped and restarted.
Stops the timer.
This method stop the timer (if currently active).