Enterabs() method of scheduler class in Python

Method Name:

enterabs

Method Signature:

enterabs(time, priority, action, argument=(), kwargs)

 

Parameters:

time – Time at which the event/action has to be executed, which is specified as  number of seconds since epoch. The time specified here is absolute time. Compare this with the time parameter of the enter() function of the scheduler class, which is the relative time.

priority – The priority of the event. When two events with the same scheduled time come for execution, the priority decides which one to execute. The Priority is interpreted in UNIX way. Lower the value, higher is the priority of the event.

action – The function that constitutes an event. The sequence of statements inside this function is executed as the event.

argument Positional arguments to the event function.

kwargs – A dictionary of keyword arguments to the event function.

 

Return Value:

Returns a named tuple for the event added to the scheduler’s Queue.

Overview:

  • The enterabs() time adds an event to the internal queue of the scheduler.
  • As the run() method of a scheduler is called, the entries in the queue of a scheduler are executed one by one.

Example:

# Example Python program that schedules events

# using the method scheduler.enterabs

import sched

import time

 

# The function that constitutes an event

def eventFunction0(message):

    print("Executing %s"%message)

 

# Another function that constitutes an event

def eventFunction1(message):

    print("Executing %s"%message)

 

# Create a scheduler

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

 

# Add events to the scheduler

scheduler.enterabs(time.time()+5, 1, eventFunction0, argument = ("Event X",));

scheduler.enterabs(time.time()+10, 2, eventFunction1, argument = ("Event Y",));

 

# Run the scheduler

scheduler.run();

 

Output:

Executing Event X

Executing Event Y

 


Copyright 2024 © pythontic.com