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
| Attribute | Type | Description |
|---|---|---|
| _Greenlet | class | A local Greenlet subclass that aliases the kill method to cancel for managing scheduled tasks. |
| _GreenletExit | exception | The exception class used to signal the termination of a greenlet task. |
| _queue | set = set() | A set containing the currently active greenlet instances scheduled by the timer. |
| queue | set | Provides access to the internal set of scheduled greenlet tasks. |
Constructor
Signature
def Timer(
*args: any,
**kwargs: any
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| *args | any | Variable length argument list passed to the parent class constructor. |
| **kwargs | any | Arbitrary 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
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
set | A set containing the active greenlet objects currently in the queue. |