Method Name
empty
Method Signature
empty()
Return Value
Returns False if the scheduler has one or more events to execute.
Returns True, if the internal queue of the scheduler is empty.
Overview
The empty() method checks whether the internal queue of a scheduler instance is empty or not and it returns True if the queue is empty. Returns False otherwise.
Example
# Example Python program to check whether the internal queue of the scheduler is empty
import sched
import time
# The function that defines the task
def taskFunction(eventid):
print("Executing event with event id:%d"%eventid);
taskScheduler = sched.scheduler(time.time, time.sleep);
# Add tasks to the scheduler
t1 = taskScheduler.enter(10, 1, taskFunction, (1,));
t2 = taskScheduler.enter(5, 1, taskFunction, (2,));
# Check whether the scheduler's queue is empty
isEmpty = taskScheduler.empty();
print("Scheduler has one or more tasks to execute:%s"%(not isEmpty));
taskScheduler.run();
# Check whether the scheduler's queue is empty
isEmpty = taskScheduler.empty();
print("Scheduler has one or more tasks to execute:%s"%(not isEmpty));Output
Scheduler has one or more tasks to execute:True
Executing event with event id:2
Executing event with event id:1
Scheduler has one or more tasks to execute:False