Queue attribute of the scheduler class

Attribute Name:

queue

Overview:

  • Refers to the internal queue maintained by a scheduler instance.
  • The queue attribute is read-only.
  • The queue is a list of named tuples where each tuple consists of the information about the event: time, priority, event function, positional arguments to the event function, keyword arguments to the event function.

Example:

  • The Python example below adds two events to a scheduler instance. One through the enterabs() method and one through enter() method.
  • As the contents of the internal queue of the scheduler instance is printed, it can be observed that the event added through enter() also has its time stored internally as absolute time.

# Example Python program that refers to the scheduler.queue

# attribute on a sched.scheduler instance

 

import sched

import time

 

# Event function

def evt(id):

    print("Event %s"%id);

 

# Create a scheduler

scheduler = sched.scheduler(time.time, time.sleep);

 

# Schedule an event with absolute time

scheduler.enterabs(time.time()+5, 1, evt, (1,));

 

# Schedule an event with relative time

scheduler.enter(10, 2, evt, (2,));

 

for anEvent in scheduler.queue:

    print(anEvent);

 

print("Starting events:");

 

# Run the event   

scheduler.run();   

 

Output:

Event(time=1574341820.263387, priority=1, action=<function evt at 0x103b0a5e0>, argument=(1,), kwargs={})

Event(time=1574341825.263394, priority=2, action=<function evt at 0x103b0a5e0>, argument=(2,), kwargs={})

Starting events:

Event 1

Event 2


Copyright 2024 © pythontic.com