Skip to main content

Timer

This class provides a timer implementation that uses greenlets to schedule and execute tasks at specific times. It supports spawning delayed operations, managing a queue of active tasks, and clearing all pending executions. The class integrates with gevent's event loop to handle task lifecycle and cancellation.

Attributes​

AttributeTypeDescription
_GreenletclassA local Greenlet subclass that aliases the kill method to cancel for managing scheduled tasks.
_GreenletExitexceptionThe exception class used to signal the termination of a greenlet task.
_queueset = set()A set containing the currently active greenlet instances scheduled by the timer.
queuesetProvides access to the internal set of scheduled greenlet tasks.

Constructor​

Signature​

def Timer(
*args: any,
**kwargs: any
) - > null

Parameters​

NameTypeDescription
*argsanyVariable length argument list passed to the parent class constructor.
**kwargsanyArbitrary keyword arguments passed to the parent class constructor.

Methods​


clear()​

@classmethod
def clear() - > null

Cancels all currently scheduled tasks and empties the timer queue. This method iterates through all active greenlets and kills them immediately.

Returns​

TypeDescription
null

queue()​

@classmethod
def queue() - > set

Provides access to the set of currently scheduled task greenlets. This property allows callers to inspect the active tasks managed by the timer.

Returns​

TypeDescription
setA set containing the active greenlet objects currently in the queue.