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
AddShortTask(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.AddShortTask(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
The time to wait in floating point seconds.
The callable to invoke after the time has elapsed.
Optional positional arguments for the callable.
Optional keyword arguments for the callable.
An object to identify the task.
AddShortTaskAbsolute(startTime, func, *args, **kwargs)¶
This does the same as
AddShortTask(), 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.AddShortTaskAbsolute(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.