eg.Scheduler

class eg.Scheduler

Sometimes you want to execute some code at a specified time or after a specified time period. EventGhost includes a small scheduler, that helps you to accomplish this.

EventGhost creates a single instance of this class that is accessible as eg.scheduler.

AddTask(waitTime, func, *args, **kwargs)

This function will call the callable func after waitTime seconds (expressed as a floating point number) with optional parameters, by adding it to the scheduler’s queue. A little example:

def MyTestFunc(myArgument):
    print "MyTestFunc was called with:", repr(myArgument)

eg.scheduler.AddTask(10.0, MyTestFunc, "just some test data")

Ten seconds after invocation of the code it will print the following message to the log:

MyTestFunc was called with: 'just some test data'

The function will return an object, that you can use as the task identifier for CancelTask().

Arguments :
waitTime

The time to wait in floating point seconds.

func

The callable to invoke after the time has elapsed.

*args

Optional positional arguments for the callable.

**kwargs

Optional keyword arguments for the callable.

Returns :

An object to identify the task.

AddTaskAbsolute(startTime, func, *args, **kwargs)

This does the same as AddTask(), but the startTime parameter specifies an absolute time expressed in floating point seconds since the epoch. Take a look at the documentation of Python’s time module, for more information about this time format. Again a little example:

import time
startTime = time.mktime((2007, 8, 15, 16, 53, 0, 0, 0, -1))
eg.scheduler.AddTaskAbsolute(startTime, eg.TriggerEvent, "MyEvent")

This will trigger the event “Main.MyEvent” at 16:53:00 on 15 August 2007. If you run this code after this point of time, the eg.TriggerEvent() will be called immediately.

CancelTask(task)

This will cancel a task formerly added by AddTask() or AddTaskAbsolute(), if the task hasn’t been started yet.

If the task has already been called or simply wasn’t added before, the function will raise an IndexError.

Previous topic

eg.PluginBase

Next topic

eg.SerialPortChoice

This Page