Timer – timer handle

class uv.Timer(loop=None, callback=None)[source]

Timer handles are used to schedule callbacks to be called in the future.

Raises:

uv.UVError – error during the initialization of the handle

Parameters:
  • loop (Loop) – event loop which should be used for the handle
  • callback ((uv.Timer) -> None) – callback which should be called on timeout
callback

Callback which should be called on timeout.

callback(Timer-Handle)
Readonly:False
Type:(uv.Timer) -> None
repeat

The repeat interval value in milliseconds. The timer will be scheduled to run on the given interval, regardless of the callback execution duration, and will follow normal timer semantics in the case of time-slice overrun.

For example, if a 50ms repeating timer first runs for 17ms, it will be scheduled to run again 33ms later. If other tasks consume more than the 33ms following the first timer callback, then the callback will run as soon as possible.

Note

If the repeat value is set from a timer callback it does not immediately take effect. If the timer was non-repeating before, it will have been stopped. If it was repeating, then the old repeat value will have been used to schedule the next timeout.

Raises:uv.HandleClosedError – handle has already been closed or is closing
Readonly:False
Return type:int
again()[source]

Stop the timer, and if it is repeating restart it using the repeat value as the timeout. If the timer has never been started before it raises uv.UVError with uv.StatusCode.EINVAL.

Raises:
start(timeout, callback=None, repeat=0)[source]

Starts the timer. If timeout is zero, the callback fires on the next event loop iteration. If repeat is non-zero, the callback fires first after timeout milliseconds and then repeatedly after repeat milliseconds.

Raises:
Parameters:
  • timeout (int) – timeout which should be used (in milliseconds)
  • callback ((uv.Timer) -> None) – callback which should be called on timeout
  • repeat (int) – repeat interval which should be set (in milliseconds)
stop()[source]

Stops the handle, the callback will no longer be called.

Raises:uv.UVError – error while stopping the handle